-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (28 loc) · 859 Bytes
/
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
const core = require('@actions/core')
const helper = require('./libs/helper.js')
const ErrorCommitBodyEmpty = 'Commit body is missing'
async function main() {
try {
const commitsString = core.getInput('commits')
const commits = JSON.parse(commitsString)
const failed = []
for (const {commit, sha} of commits) {
const lines = commit.message.split('\n')
const validLines = lines.filter(line => line.trim() && !isDco(line))
if (validLines.length <= 1) {
failed.push({sha, message: ErrorCommitBodyEmpty})
}
}
if (failed.length > 0) {
const summary = helper.getOutput(failed)
core.setFailed(summary)
}
} catch (error) {
core.setFailed(error.message)
}
}
function isDco(text) {
const re = /^Signed-off-by: ([^<]+) <([^<>@]+@[^<>]+)>$/gim
return re.test(text)
}
main()