generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
53 lines (45 loc) · 1.53 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
43
44
45
46
47
48
49
50
51
52
53
const core = require('@actions/core')
const github = require('@actions/github')
const check = require('./src/checks')
// most @actions toolkit packages have async methods
async function run() {
try {
const pr = github.context.payload.pull_request
const skipKey = core.getInput("skip-key", {required: false}) || "URGENT"
if (pr.title.indexOf(skipKey) !== -1) {
core.warning(`[${skipKey}] in title, check skipped!!!`)
return
}
const exemptUsersStr = core.getInput("exempt-users")
if (exemptUsersStr) {
let exemptUsers = []
const ghUserName = pr.user.login
/* eslint no-empty: ["error", { "allowEmptyCatch": true }] */
try {
exemptUsers = JSON.parse(exemptUsersStr)
} catch (e) {}
if (exemptUsers.indexOf(ghUserName) !== -1) {
core.warning(`[${ghUserName}] was in exempted list, check skipped!!!`)
return
}
}
const checkItemStr = core.getInput('check-items') || "all";
let checkItems = null
try {
checkItems = JSON.parse(checkItemStr)
} catch(e) {
checkItems = checkItemStr
}
const checkResults = check(pr, checkItems)
checkResults.forEach(cr => {
core.info(`Check for "${cr.checkItem}" ${cr.success ? "successful" : "failure"}: ${cr.message}`)
})
const failures = checkResults.filter(r => !r.success)
if (failures.length > 0) {
core.setFailed("These items check failed: " + failures.map(r => r.checkItem).join(", "))
}
} catch (error) {
core.setFailed(error.message);
}
}
run();