@@ -4,6 +4,7 @@ import {getInput} from "@actions/core"
44import { exec } from "@actions/exec"
55import { context , GitHub } from "@actions/github"
66import chalk from "chalk"
7+ import getBooleanActionInput from "get-boolean-action-input"
78import isGitRepoDirty from "is-git-repo-dirty"
89import nanoid from "nanoid"
910import resolveAny from "resolve-any"
@@ -16,11 +17,26 @@ import zahl from "zahl"
1617 * @prop {* } pullRequestTitle If a function is given, it will be called as `async function(commitManager)`
1718 * @prop {* } pullRequestBody If a function is given, it will be called as `async function(commitManager)`
1819 * @prop {* } branchPrefix If a function is given, it will be called as `async function(commitManager)`
19- * @prop {boolean } autoApprove
20- * @prop {boolean } autoRemoveBranch
20+ * @prop {boolean|string } autoApprove
21+ * @prop {boolean|string } autoRemoveBranch
2122 * @prop {string } githubTokenInputName
2223 */
2324
25+ /**
26+ * @param {string|boolean } value
27+ * @param {boolean } defaultValue
28+ * @return {boolean }
29+ */
30+ function getBooleanValue ( value , defaultValue ) {
31+ if ( value === undefined ) {
32+ return defaultValue
33+ }
34+ if ( typeof value === "string" ) {
35+ return getBooleanActionInput ( value )
36+ }
37+ return Boolean ( value )
38+ }
39+
2440/**
2541 * @example
2642 * import CommitManager from "commit-from-action"
@@ -69,6 +85,8 @@ export default class CommitManager {
6985 branchPrefix : "action-" ,
7086 ...options ,
7187 }
88+ this . autoApprove = getBooleanValue ( this . options . autoApprove , true )
89+ this . autoRemoveBranch = getBooleanValue ( this . options . autoRemoveBranch , true )
7290 }
7391
7492 /**
@@ -137,7 +155,7 @@ export default class CommitManager {
137155 this . pullNumber = pullCreateResult . data . number
138156 const pullLink = `https://github.com/${ process . env . GITHUB_REPOSITORY } /pull/${ this . pullNumber } `
139157 console . log ( `Pull with ${ zahl ( this . commits , "commit" ) } created: ${ chalk . greenBright ( pullLink ) } ` )
140- if ( ! this . options . autoApprove ) {
158+ if ( ! this . autoApprove ) {
141159 return
142160 }
143161 await octokit . pulls . merge ( {
@@ -146,7 +164,7 @@ export default class CommitManager {
146164 commit_title : await resolveAny ( this . options . mergeMessage , this ) ,
147165 } )
148166 this . isMerged = true
149- if ( ! this . options . autoRemoveBranch ) {
167+ if ( ! this . autoRemoveBranch ) {
150168 return
151169 }
152170 await octokit . git . deleteRef ( {
@@ -160,7 +178,7 @@ export default class CommitManager {
160178 if ( ! this . pullNumber ) {
161179 return // Pull request does not exist, nothing to clean
162180 }
163- if ( this . options . autoApprove && ! this . isMerged ) {
181+ if ( this . autoApprove && ! this . isMerged ) {
164182 console . log ( `Automerging failed, pull #${ this . pullNumber } will be closed now` )
165183 const octokit = new GitHub ( this . githubToken )
166184 await octokit . pulls . update ( {
0 commit comments