forked from fastify/github-action-merge-dependabot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
util.js
51 lines (41 loc) · 1.28 KB
/
util.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict'
const { mapUpdateType } = require('./mapUpdateType')
const { logWarning } = require('./log')
const mergeMethods = {
merge: 'merge',
squash: 'squash',
rebase: 'rebase',
}
const getMergeMethod = inputs => {
const input = inputs['merge-method']
if (!input) {
return mergeMethods.squash
}
if (!mergeMethods[input]) {
logWarning(
'merge-method input is ignored because it is malformed, defaulting to `squash`.'
)
return mergeMethods.squash
}
return mergeMethods[input]
}
const parseCommaOrSemicolonSeparatedValue = value => {
return value ? value.split(/[;,]/).map(el => el.trim()) : []
}
exports.parseCommaOrSemicolonSeparatedValue =
parseCommaOrSemicolonSeparatedValue
exports.getInputs = inputs => {
if (!inputs) {
throw new Error('Invalid inputs object passed to getInputs')
}
return {
MERGE_METHOD: getMergeMethod(inputs),
EXCLUDE_PKGS: parseCommaOrSemicolonSeparatedValue(inputs['exclude']),
MERGE_COMMENT: inputs['merge-comment'] || '',
APPROVE_ONLY: /true/i.test(inputs['approve-only']),
USE_GITHUB_AUTO_MERGE: /true/i.test(inputs['use-github-auto-merge']),
TARGET: mapUpdateType(inputs['target']),
PR_NUMBER: inputs['pr-number'],
SKIP_COMMIT_VERIFICATION: inputs['skip-commit-verification'],
}
}