From fbb489b9b67f4606de7ce9557f5488ae9776c318 Mon Sep 17 00:00:00 2001 From: Jonathan Rubenstein Date: Sun, 16 Feb 2025 21:03:33 +0200 Subject: [PATCH] [github] pr-check: Automatically add review requesting changes when PR author is not found in AUTHORS --- .github/workflows/pr-check.yml | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 353a59db..33d7dad5 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -3,16 +3,36 @@ on: pull_request jobs: authors: runs-on: ubuntu-latest + permissions: + pull-requests: write steps: - uses: actions/checkout@v1 - name: Check AUTHORS file + id: check-authors run: | user="$(curl -H 'Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' -s https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }} | jq -r .user.login)" + echo "user=$user" >> "$GITHUB_OUTPUT" echo "Checking if GitHub user $user is in AUTHORS file..." if grep -q -E '> \('"$user"'\)' AUTHORS; then echo "$user found in AUTHORS file, all good!" else echo "$user not found in AUTHORS file." echo "Please add yourself to the AUTHORS file and try again." - exit 1 + echo "not-found=yes" >> "$GITHUB_OUTPUT" fi + - name: 'Not found: Create review requesting changes' + if: ${{ steps.check-authors.outputs.not-found }} + uses: actions/github-script@v7 + with: + script: | + github.rest.pulls.createReview({ + owner: context.issue.owner, + repo: context.issue.repo, + pull_number: context.issue.number, + event: "REQUEST_CHANGES", + body: "@${{ steps.check-authors.outputs.user }} not found in AUTHORS file.\n" + + "Please add yourself to the AUTHORS file and try again." + }); + - name: 'Not found: Fail job' + if: ${{ steps.check-authors.outputs.not-found }} + run: exit 1