name: "Check PR template was used"
on:
pull_request_target:
types: [opened]
permissions: {}
jobs:
main:
name: Validate PR description
runs-on: ubuntu-latest
permissions:
contents: read
issues: write pull-requests: write steps:
- env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MARKER: "<!-- Magic marker that you used the PR template; DO NOT EDIT OR REMOVE THIS COMMENT! -->"
MSG: >
Thanks for contributing to Topgrade! We require all contributions to use and fill out the PR template,
which it appears you did not. If this is a mistake, please re-open this PR and leave a comment.
Otherwise, please open a new PR using the template.
Note that we do not allow AI agents to interact with this repository, only humans are allowed to open PRs.
REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}
AUTHOR: ${{ github.event.pull_request.user.login }}
BODY: ${{ github.event.pull_request.body }}
run: |
PERM=$(gh api repos/$REPO/collaborators/$AUTHOR/permission --jq .permission)
echo "Author: $AUTHOR"
if [[ "$PERM" == "admin" || "$PERM" == "maintain" ]]; then
echo "This user has permission '$PERM', skipping PR description check"
exit 0
fi
TYPE=$(gh api users/$AUTHOR --jq .type)
if [[ "$TYPE" == "Bot" ]]; then
echo "This user is a bot, skipping PR description check"
exit 0
fi
if [[ "$BODY" != *"$MARKER"* ]]; then
echo "Did not find '$MARKER' in PR body, closing..."
gh pr comment --repo "$REPO" "$PR" --body "$MSG"
gh pr close --repo "$REPO" "$PR"
fi