Skip to content
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
33 changes: 28 additions & 5 deletions .github/workflows/pkgcheck-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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

Expand Down Expand Up @@ -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 changes: 0 additions & 21 deletions .github/workflows/pkgcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/pr-rules.yml
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions scripts/pr-template.sh
Original file line number Diff line number Diff line change
@@ -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
Loading