forked from zwaldowski/match-label-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (39 loc) · 1.12 KB
/
index.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
const core = require('@actions/core')
const github = require('@actions/github')
const match = require('./match.js')
function run() {
try {
const pr = github.context.payload.pull_request || {}
const labels = pr.labels || []
const labelNames = labels.map((label) => label.name)
const allowedLabels = match.parseAllowed(core.getInput('allowed'))
const allowedMultipleLabels = match.parseAllowed(
core.getInput('allowed_multiple')
)
const defaultMatch = core.getInput('default_match')
let matchingLabel
if (allowedLabels.length > 0) {
matchingLabel = match.findMatching(
labelNames,
allowedLabels,
false,
defaultMatch
)
} else if (allowedMultipleLabels.length > 0) {
matchingLabel = match.findMatching(
labelNames,
allowedMultipleLabels,
true,
defaultMatch
)
} else {
return core.setFailed(
'You must provide either `allowed` or `allowed_multiple` as input.'
)
}
core.setOutput('match', matchingLabel.join(', '))
} catch (error) {
core.setFailed(error.message)
}
}
run()