-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (38 loc) · 1.41 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
const core = require('@actions/core');
const github = require('@actions/github');
const re = new RegExp(/(?<=```release-note\s*)(.*?)(?=\s*```)/, 's');
try {
const labelName = core.getInput('label-name');
const context = github.context;
const labels = context.payload.pull_request.labels;
const prBody = context.payload.pull_request.body;
const labels_names = labels.map(item => item.name)
var failureMessage = ""
if (labels_names.includes(labelName)) {
var match = re.exec(prBody);
if (match == null) {
failureMessage = "No release notes found in PR body"
} else {
var releaseNotes = match[0].trim();
if (releaseNotes.toUpperCase() == "TBD") {
failureMessage = "Release notes are still TBD"
}
if (releaseNotes == "") {
failureMessage = "Release notes are empty"
}
}
} else {
console.log("Label " + labelName + " not present, skipping validation")
}
if (failureMessage != "") {
if (context.payload.pull_request.draft == true) {
console.log("[draft] PR contained the following issue: " + failureMessage)
} else {
core.setFailed("An error was found: " + failureMessage)
}
} else {
console.log("No errors detected in release notes.")
}
} catch (error) {
core.setFailed(error.message);
}