Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow to check checklist #18

Merged
merged 2 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

> 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.

## Checklist
<h2 id="checklist">Checklist</h2>

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.

Expand All @@ -19,11 +19,10 @@ The following is a best-effort checklist. If any items in this checklist aren't
- [ ] I have updated the side navigation as necessary.
- [ ] I have updated the documentation to reflect the changes.
- [ ] I have documented or updated any remaining open issues linked to this PR in GitHub, Obsidian, etc.
- [ ] I have checked that my changes look as expected on a locally built version of the docs site.

### Build, deploy, and test

- [ ] I have merged and published any dependent changes in other PRs.
- [ ] I have commented my code, particularly in hard-to-understand areas.
- [ ] I have confirmed that the application builds and deploys as expected.
- [ ] I have checked that my changes look as expected on a locally built version of the docs site.
- [ ] My changes generate no new warnings.
81 changes: 81 additions & 0 deletions .github/workflows/check-checklist.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: PR checklist checker

on:
pull_request:
types: [opened, edited, reopened, synchronize]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
check-checklist:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

# Wait 15 seconds so that the job doesn't run immediately when checking off multiple items in the checklist.
# - name: Wait for 15 seconds
# run: |
# sleep 15

- name: Check checklist in PR description
id: check_checklist
run: |
DESCRIPTION=$(jq -r .pull_request.body < $GITHUB_EVENT_PATH)
UNCHECKED_ITEMS=$(echo "$DESCRIPTION" | grep -o '.*\[ \].*' || true)
if [ -z "$UNCHECKED_ITEMS" ]; then
echo "all_checked=true" >> $GITHUB_ENV
else
echo "all_checked=false" >> $GITHUB_ENV
echo "unchecked_items<<EOF" >> $GITHUB_ENV
echo "$UNCHECKED_ITEMS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
fi

- name: Debug PR body
run: |
curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r '.body'

- name: Leave a comment
if: env.all_checked == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "All items in the checklist have been checked🎉"
})

- name: Leave a comment with unchecked items
if: env.all_checked == 'false'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number
});
const assignee = pullRequest.assignee ? `@${pullRequest.assignee.login}` : 'No assignee';
const uncheckedItems = process.env.unchecked_items.split('\n').map(item => `- ${item}`).join('\n');
const prLink = `https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${context.issue.number}`;
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `${assignee} Not all items in the checklist have been checked👀\n\nPlease review the unchecked items in the [PR description](${prLink}#checklist).`
})

- name: Fail the job if not all items are checked
if: env.all_checked == 'false'
run: |
echo "Failing the job because not all items in the checklist have been checked."
exit 1
Loading