forked from ukama/ukama
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dangerfile.ts
49 lines (39 loc) · 1.56 KB
/
dangerfile.ts
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
import {message, danger} from "danger"
const pr = danger.github.pr
// No PR is too small to include a description of why you made a change
if (pr.mergeable_state != 'draft' ){
if (pr.body === null || pr.body.length < 20) {
fail('Please include a description of your PR changes.');
} else {
var match = pr.body.match(/\bResolves #(\d*)\b/i);
if (match === null){
match = pr.body.match(/\Fixes #(\d*)\b/i);
}
if (match !== null){
const issueNumber = match.pop();
const intIssueNum = parseInt(issueNumber)
if (issueNumber === undefined || intIssueNum === undefined){
warn("Error parsing the issue number");
return;
}
danger.github.api.issues.get({
issue_number: intIssueNum,
owner: danger.github.thisPR.owner,
repo: danger.github.thisPR.repo,
}).catch(error => {
if (error.status === 404) {
fail(`Cannot find issue #${issueNumber}`);
} else if (error.status !== 200) {
warn(`Unable to check issue #${intIssueNum}. Error status: ${error.status}. Error data: ${error}`);
}
})
}else{
fail("PR does not have a reference to an issue in the description. Consider adding something like `Fixes #123`");
}
}
// // Always ensure we assign someone to a PR, if its a
// if (pr.assignee === null) {
// //const method = pr.title.includes("WIP") ? warn : fail
// warn("Please assign someone to this PR.");
// }
}