Skip to content

Commit 7644066

Browse files
committed
feat: make merge_method configurable
1 parent cc8a21e commit 7644066

File tree

5 files changed

+47
-10
lines changed

5 files changed

+47
-10
lines changed

action.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ inputs:
88
description: "Packages that you want to manually review before upgrading"
99
required: false
1010
default: []
11+
merge-method:
12+
description: "The merge method you would like to use (squash, merge, rebase)"
13+
required: false
14+
default: "squash"
1115
runs:
1216
using: "node12"
13-
main: "index.js"
17+
main: "src/index.js"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "github-action-merge-dependabot",
33
"version": "1.0.1",
44
"description": "",
5-
"main": "index.js",
5+
"main": "src/index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},

index.js renamed to src/index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
const core = require('@actions/core')
22
const github = require('@actions/github')
33

4-
const GITHUB_TOKEN = core.getInput('github-token', { required: true })
5-
const EXCLUDE_PKGS = core.getInput('exclude') || []
4+
const { getInputs } = require('./util')
65

7-
const getMergeMethod = (repo) => {
8-
if (repo.allow_merge_commit) return 'merge'
9-
if (repo.allow_squash_merge) return 'squash'
10-
return 'rebase'
11-
}
6+
const { GITHUB_TOKEN, MERGE_METHOD, EXCLUDE_PKGS } = getInputs()
127

138
async function run () {
149
try {
@@ -43,7 +38,7 @@ async function run () {
4338
owner,
4439
repo,
4540
pull_number: prNumber,
46-
merge_method: getMergeMethod(pr.head.repo)
41+
merge_method: MERGE_METHOD
4742
})
4843
} catch (error) {
4944
core.setFailed(error.message)

src/log.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const { debug, error, info, warning } = require('@actions/core')
2+
3+
const stringify = (msg) => (
4+
typeof msg === 'string' ? msg : (msg.stack || msg.toString())
5+
)
6+
7+
const log = logger => message => logger(stringify(message))
8+
9+
exports.logDebug = log(debug)
10+
exports.logError = log(error)
11+
exports.logInfo = log(info)
12+
exports.logWarning = log(warning)

src/util.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const core = require('@actions/core')
2+
3+
const { logWarning } = require('./log')
4+
5+
const mergeMethods = {
6+
merge: 'merge',
7+
squash: 'squash',
8+
rebase: 'rebase'
9+
}
10+
11+
const getMergeMethod = () => {
12+
const input = core.getInput('merge-method')
13+
14+
if (!input || !mergeMethods[input]) {
15+
logWarning('merge-method input is ignored because it is malformed, defaulting to `squash`.')
16+
return mergeMethods.squash
17+
}
18+
19+
return mergeMethods[input]
20+
}
21+
22+
exports.getInputs = () => ({
23+
GITHUB_TOKEN: core.getInput('github-token', { required: true }),
24+
MERGE_METHOD: getMergeMethod(),
25+
EXCLUDE_PKGS: core.getInput('exclude') || []
26+
})

0 commit comments

Comments
 (0)