generated from hackforla/.github-hackforla-base-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 61
63 lines (55 loc) · 2.35 KB
/
compliance.yaml
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
54
55
56
57
58
59
60
61
62
63
name: Compliance
on:
pull_request_target:
types:
- opened
- edited
- synchronize
- reopened
- unassigned
jobs:
check-for-linked-issue:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Check for keyword and issue number
id: check-for-keyword
uses: actions/github-script@v7
with:
script: |
// Retrieve body of context.payload and search for GitHub keywords
const prBody = context.payload.pull_request.body;
const prNumber = context.payload.pull_request.number;
const prOwner = context.payload.pull_request.user.login;
const regex = /(?<!Example:\s*)(close|closes|closed|fix|fixes|fixed|resolve|resolves|resolved)\s+#(\d+)/i;
const match = prBody.match(regex);
let prComment;
if (!match) {
console.log('PR does not have a properly linked issue. Posting comment...');
prComment = `@${prOwner}, this Pull Request is not linked to a valid issue. Please provide a valid linked issue in "Related Issues" above, using the format of "Resolves #" + issue number.`;
}
else {
let [ , keyword, linkNumber ] = match;
console.log('Found a keyword: \'' + keyword + '\'. Checking for legitimate linked issue...');
try {
const response = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: linkNumber,
});
console.log('Found an issue: \'#' + linkNumber + '\' in repo. Reference is a legitimate linked issue.');
}
catch (error) {
console.log('Couldn\'t find issue #' + linkNumber + ' in repo. Posting comment...');
prComment = `@${prOwner}, the issue number referenced above as "**${keyword} #${linkNumber}**" is not found. Please replace with a valid issue number.`;
}
}
if (prComment) {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: prComment,
});
}