.github: check commit rules and the PR template in pr-rules

Contributors delete the template, so reviewers cannot see whether
pkgcheck ran or AI was used. The boxes stay optional because not every
contributor can run pkgcheck with --net and the AI box applies only when
AI was used. The autobump bot does not fill in the template and is
skipped.

The commit rules move from pkgcheck into the same workflow, because both
checks read the pull request rather than the ebuilds and must rerun when
the description is edited, which pkgcheck should not.

pkgcheck-comment now also closes a pull request without the template,
and its reply lists the commit and template problems in separate
sections.

Signed-off-by: Zakk <zakk@gentoozh.org>
This commit is contained in:
Zakk committed 2026-10-11 05:45:11 +11:00
1 parent e450ab84e2
commit d09a49ff02
4 files changed
+80 -26

No files matched your search

+28 -5
View File
@@ -44,7 +44,7 @@ jobs:
RUN_URL: ${{ github.event.workflow_run.html_url }}
run: scripts/pkgcheck-comment.sh pkgcheck-report
- name: close a pull request with malformed commits
- name: close a pull request that breaks the pull request rules
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
@@ -53,9 +53,15 @@ jobs:
pr=$(jq -r --arg sha "$HEAD_SHA" 'first(.[][] | select(.head.sha == $sha) | .number) // empty' <<< "$pulls")
[ -n "$pr" ] || exit 0
bad=$(scripts/commit-rules.sh "$pr")
[ -n "$bad" ] || exit 0
cat > body.md <<EOF
This pull request was closed automatically because these commits break the commit rules:
missing=$(scripts/pr-template.sh "$pr")
[ -n "$bad$missing" ] || exit 0
echo "This pull request was closed automatically because it breaks the rules below." > body.md
if [ -n "$bad" ]; then
cat >> body.md <<EOF
## Commits
These commits break the commit rules:
$bad
@@ -84,6 +90,23 @@ jobs:
git push --force-with-lease
\`\`\`
A closed pull request cannot be reopened after a force push, so open a new one. See [CONTRIBUTING.en.md](https://github.com/gentoo-zh/overlay/blob/master/CONTRIBUTING.en.md).
A closed pull request cannot be reopened after a force push.
EOF
fi
if [ -n "$missing" ]; then
cat >> body.md <<EOF
## Pull request template
The description lost these checkboxes of the [pull request template](https://github.com/gentoo-zh/overlay/blob/master/.github/pull_request_template.md):
$missing
Write the description above the template and keep the checkboxes. Leave a box unticked when it does not apply.
EOF
fi
cat >> body.md <<EOF
Fix the problems above and open a new pull request. See [CONTRIBUTING.en.md](https://github.com/gentoo-zh/overlay/blob/master/CONTRIBUTING.en.md).
EOF
gh pr close "$pr" -R "$GITHUB_REPOSITORY" --comment "$(cat body.md)"
-21
View File
@@ -23,27 +23,6 @@ jobs:
with:
args: --checks=-RedundantVersionCheck --keywords=-NonsolvableDepsInDev --exit=NonexistentDeps
commits:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: read
steps:
- name: checkout
uses: actions/checkout@v7
- name: check the commit rules
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
run: |
bad=$(scripts/commit-rules.sh "$PR")
if [ -n "$bad" ]; then
printf '%s\n' "$bad"
exit 1
fi
# Ebuilds execute PR code; the write token belongs to pkgcheck-comment.
report:
if: github.event_name == 'pull_request'
+41
View File
@@ -0,0 +1,41 @@
name: pr-rules
on:
pull_request:
branches:
- master
# edited reruns the check after the description is fixed, without rerunning pkgcheck
types: [opened, reopened, synchronize, edited]
permissions:
contents: read
pull-requests: read
jobs:
pr-rules:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v7
- name: check the commit rules
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
run: |
bad=$(scripts/commit-rules.sh "$PR")
if [ -n "$bad" ]; then
printf '%s\n' "$bad"
exit 1
fi
- name: check that the pull request template is kept
if: ${{ !cancelled() }}
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.number }}
run: |
missing=$(scripts/pr-template.sh "$PR")
if [ -n "$missing" ]; then
printf 'The description lost these checkboxes of the pull request template:\n%s\n' "$missing"
exit 1
fi
+11
View File
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# usage: pr-template.sh <pull request number>
# prints the checkboxes of .github/pull_request_template.md missing from the pull request description
set -euo pipefail
pr=$(gh api "repos/$GITHUB_REPOSITORY/pulls/${1:?pull request number}")
[ "$(jq -r .user.login <<< "$pr")" != 'gentoo-zh-autobump[bot]' ] || exit 0
body=$(jq -r '.body // ""' <<< "$pr")
# shellcheck disable=SC2016 # literal backticks of the template
for box in 'I have run `pkgcheck scan --commits --net`' 'If I used AI:'; do
grep -iF -- "$box" <<< "$body" | grep -qE '^- \[[ xX]\] ' || echo "- $box"
done