Skip to content

Commit fbb489b

Browse files
JJRcopgnif
authored andcommitted
[github] pr-check: Automatically add review requesting changes when PR author is not found in AUTHORS
1 parent 03ca20d commit fbb489b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

.github/workflows/pr-check.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,36 @@ on: pull_request
33
jobs:
44
authors:
55
runs-on: ubuntu-latest
6+
permissions:
7+
pull-requests: write
68
steps:
79
- uses: actions/checkout@v1
810
- name: Check AUTHORS file
11+
id: check-authors
912
run: |
1013
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)"
14+
echo "user=$user" >> "$GITHUB_OUTPUT"
1115
echo "Checking if GitHub user $user is in AUTHORS file..."
1216
if grep -q -E '> \('"$user"'\)' AUTHORS; then
1317
echo "$user found in AUTHORS file, all good!"
1418
else
1519
echo "$user not found in AUTHORS file."
1620
echo "Please add yourself to the AUTHORS file and try again."
17-
exit 1
21+
echo "not-found=yes" >> "$GITHUB_OUTPUT"
1822
fi
23+
- name: 'Not found: Create review requesting changes'
24+
if: ${{ steps.check-authors.outputs.not-found }}
25+
uses: actions/github-script@v7
26+
with:
27+
script: |
28+
github.rest.pulls.createReview({
29+
owner: context.issue.owner,
30+
repo: context.issue.repo,
31+
pull_number: context.issue.number,
32+
event: "REQUEST_CHANGES",
33+
body: "@${{ steps.check-authors.outputs.user }} not found in AUTHORS file.\n" +
34+
"Please add yourself to the AUTHORS file and try again."
35+
});
36+
- name: 'Not found: Fail job'
37+
if: ${{ steps.check-authors.outputs.not-found }}
38+
run: exit 1

0 commit comments

Comments
 (0)