-
Notifications
You must be signed in to change notification settings - Fork 624
61 lines (54 loc) · 2.11 KB
/
pr_checkboxes.yml
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
name: "pr_checkboxes"
on:
pull_request_target:
types: [opened]
issues:
types: [opened]
jobs:
Check_Checkboxes:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/github-script@v7
with:
script: |
function count_instances(string, word)
{
return string.split(word).length - 1;
}
const event_type = "${{ github.event_name }}"
var checkbox_total = 3
var body_text = ""
var type_name = ""
if (event_type === "pull_request_target")
{
body_text = context.payload.pull_request.body
type_name = "PR"
checkbox_total = 4
}
else // issue
{
body_text = context.payload.issue.body
type_name = "report"
}
// Remove block comments
body_text = body_text.replaceAll(/<!--.*-->/g, "")
console.log(`github.event_name: ${event_type}`)
console.log(`body_text: ${body_text}`)
console.log(`type_name: ${type_name}`)
// Count the filled in checkboxes, comparing checkbox_count to checkbox_total
const checkbox_count = count_instances(body_text, "[x]")
if (checkbox_count < checkbox_total)
{
console.log(`Found ${checkbox_count} completed checkboxes. Leaving a reminder comment.`)
const result = await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `✨ Thanks for the ${type_name}! ✨\n\nThis is a friendly automated reminder that the maintainers won't look at your ${type_name} until you've properly completed all of the checkboxes in the pre-filled template.`
})
}
else
{
console.log(`Found ${checkbox_count} completed checkboxes. All is well.`)
}