Skip to content

Commit

Permalink
feat: make merge_method configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
salmanm committed Nov 18, 2020
1 parent cc8a21e commit 7644066
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
6 changes: 5 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ inputs:
description: "Packages that you want to manually review before upgrading"
required: false
default: []
merge-method:
description: "The merge method you would like to use (squash, merge, rebase)"
required: false
default: "squash"
runs:
using: "node12"
main: "index.js"
main: "src/index.js"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "github-action-merge-dependabot",
"version": "1.0.1",
"description": "",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
11 changes: 3 additions & 8 deletions index.js → src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
const core = require('@actions/core')
const github = require('@actions/github')

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

const getMergeMethod = (repo) => {
if (repo.allow_merge_commit) return 'merge'
if (repo.allow_squash_merge) return 'squash'
return 'rebase'
}
const { GITHUB_TOKEN, MERGE_METHOD, EXCLUDE_PKGS } = getInputs()

async function run () {
try {
Expand Down Expand Up @@ -43,7 +38,7 @@ async function run () {
owner,
repo,
pull_number: prNumber,
merge_method: getMergeMethod(pr.head.repo)
merge_method: MERGE_METHOD
})
} catch (error) {
core.setFailed(error.message)
Expand Down
12 changes: 12 additions & 0 deletions src/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { debug, error, info, warning } = require('@actions/core')

const stringify = (msg) => (
typeof msg === 'string' ? msg : (msg.stack || msg.toString())
)

const log = logger => message => logger(stringify(message))

exports.logDebug = log(debug)
exports.logError = log(error)
exports.logInfo = log(info)
exports.logWarning = log(warning)
26 changes: 26 additions & 0 deletions src/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const core = require('@actions/core')

const { logWarning } = require('./log')

const mergeMethods = {
merge: 'merge',
squash: 'squash',
rebase: 'rebase'
}

const getMergeMethod = () => {
const input = core.getInput('merge-method')

if (!input || !mergeMethods[input]) {
logWarning('merge-method input is ignored because it is malformed, defaulting to `squash`.')
return mergeMethods.squash
}

return mergeMethods[input]
}

exports.getInputs = () => ({
GITHUB_TOKEN: core.getInput('github-token', { required: true }),
MERGE_METHOD: getMergeMethod(),
EXCLUDE_PKGS: core.getInput('exclude') || []
})

0 comments on commit 7644066

Please sign in to comment.