-
Notifications
You must be signed in to change notification settings - Fork 0
52 lines (42 loc) · 1.81 KB
/
reject-game.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
name: Close Linked Issue When PR is Closed
on:
pull_request:
types:
- closed
jobs:
close-linked-issue:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Get linked issue from PR
id: get-issue
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
REPO=${{ github.repository }}
# Ensure the PR has a linked issue by looking for the 'Linked issues' section
# The 'Linked issues' should appear under 'pull_request' body metadata
if [[ -z "${{ github.event.pull_request.body }}" ]]; then
echo "No linked issue found."
exit 0
fi
# Check if the PR's body contains an issue reference like "#123"
ISSUE_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -oE '#[0-9]+' | head -1 | tr -d '#')
if [[ -z "$ISSUE_NUMBER" ]]; then
echo "No linked issue found."
exit 0
fi
echo "issue=$ISSUE_NUMBER" >> $GITHUB_ENV
- name: Close the linked issue
if: env.issue != ''
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
ISSUE_NUMBER=${{ env.issue }}
REPO=${{ github.repository }}
# Close the issue with "not planned" reason
gh api -X PATCH repos/$REPO/issues/$ISSUE_NUMBER -f state="closed" -f state_reason="not_planned" -H "Authorization: Bearer $GITHUB_TOKEN"
# Add a comment to the issue
gh api repos/$REPO/issues/$ISSUE_NUMBER/comments -f body="This game is not eligible to be added. If you think this is a mistake, please review the details and create a new issue instead." -H "Authorization: Bearer $GITHUB_TOKEN"