Skip to content

Commit f15ed3b

Browse files
committed
feat: Option autoApprove and option autoRemoveBranch can now be string
Signed-off-by: Jaid <jaid.jsx@gmail.com>
1 parent 2c73211 commit f15ed3b

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@actions/github": "^2.1.1",
99
"@babel/runtime": "^7.9.2",
1010
"chalk": "^4.0.0",
11+
"get-boolean-action-input": "^1.0.2",
1112
"is-git-repo-dirty": "^1.0.1",
1213
"nanoid": "^3.1.3",
1314
"resolve-any": "^2.0.0",

src/index.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {getInput} from "@actions/core"
44
import {exec} from "@actions/exec"
55
import {context, GitHub} from "@actions/github"
66
import chalk from "chalk"
7+
import getBooleanActionInput from "get-boolean-action-input"
78
import isGitRepoDirty from "is-git-repo-dirty"
89
import nanoid from "nanoid"
910
import 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

Comments
 (0)