Skip to content

Commit de81671

Browse files
authored
Merge pull request #2 from josh-wong/add-checklist-checking-workflow-and-pr-template
Add workflow to check checklist and PR template
2 parents 88119ca + 70590e9 commit de81671

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed

.github/pull_request_template.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Description
2+
3+
> Replace this text with a brief description about **why** this PR is necessary. Be sure to provide context.
4+
5+
## Related issues and/or PRs
6+
7+
> Replace this text with links to any existing issues and/or PRs. Or, write `N/A` if no related issues and/or PRs exist.
8+
9+
## Changes made
10+
11+
> Replace this text with an outline the specific changes made in this pull request in the form of a bulleted list. Include relevant details, such as added features, bug fixes, code refactoring, or improvements.
12+
13+
<h2 id="checklist">Checklist</h2>
14+
15+
The following is a best-effort checklist. If any items in this checklist aren't applicable to this PR, add `N/A` after each item.
16+
17+
### Documentation
18+
19+
- [ ] I have updated the side navigation as necessary.
20+
- [ ] I have updated the documentation to reflect the changes.
21+
- [ ] I have documented or updated any remaining open issues linked to this PR in GitHub, Obsidian, etc.
22+
23+
### Build, deploy, and test
24+
25+
- [ ] I have merged and published any dependent changes in other PRs.
26+
- [ ] I have commented my code, particularly in hard-to-understand areas.
27+
- [ ] I have checked that my changes look as expected on a locally built version of the docs site.
28+
- [ ] My changes generate no new warnings.

.github/workflows/check-checklist.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: PR checklist checker
2+
3+
on:
4+
pull_request:
5+
types: [opened, edited, reopened, synchronize]
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
9+
cancel-in-progress: true
10+
11+
jobs:
12+
check-checklist:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
# Wait 15 seconds so that the job doesn't run immediately when checking off multiple items in the checklist.
20+
# - name: Wait for 15 seconds
21+
# run: |
22+
# sleep 15
23+
24+
- name: Check checklist in PR description
25+
id: check_checklist
26+
run: |
27+
DESCRIPTION=$(jq -r .pull_request.body < $GITHUB_EVENT_PATH)
28+
UNCHECKED_ITEMS=$(echo "$DESCRIPTION" | grep -o '.*\[ \].*' || true)
29+
if [ -z "$UNCHECKED_ITEMS" ]; then
30+
echo "all_checked=true" >> $GITHUB_ENV
31+
else
32+
echo "all_checked=false" >> $GITHUB_ENV
33+
echo "unchecked_items<<EOF" >> $GITHUB_ENV
34+
echo "$UNCHECKED_ITEMS" >> $GITHUB_ENV
35+
echo "EOF" >> $GITHUB_ENV
36+
fi
37+
38+
- name: Debug PR body
39+
run: |
40+
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
41+
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r '.body'
42+
43+
- name: Leave a comment
44+
if: env.all_checked == 'true'
45+
uses: actions/github-script@v6
46+
with:
47+
github-token: ${{ secrets.GITHUB_TOKEN }}
48+
script: |
49+
github.rest.issues.createComment({
50+
issue_number: context.issue.number,
51+
owner: context.repo.owner,
52+
repo: context.repo.repo,
53+
body: "All items in the checklist have been checked🎉"
54+
})
55+
56+
- name: Leave a comment with unchecked items
57+
if: env.all_checked == 'false'
58+
uses: actions/github-script@v6
59+
with:
60+
github-token: ${{ secrets.GITHUB_TOKEN }}
61+
script: |
62+
const { data: pullRequest } = await github.rest.pulls.get({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
pull_number: context.issue.number
66+
});
67+
const assignee = pullRequest.assignee ? `@${pullRequest.assignee.login}` : 'No assignee';
68+
const uncheckedItems = process.env.unchecked_items.split('\n').map(item => `- ${item}`).join('\n');
69+
const prLink = `https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.number}`;
70+
github.rest.issues.createComment({
71+
issue_number: context.issue.number,
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
body: `${assignee} Not all items in the checklist have been checked👀\n\nPlease review the unchecked items in the [PR description](${prLink}#checklist).`
75+
})
76+
77+
- name: Fail the job if not all items are checked
78+
if: env.all_checked == 'false'
79+
run: |
80+
echo "Failing the job because not all items in the checklist have been checked."
81+
exit 1

0 commit comments

Comments
 (0)