-
Notifications
You must be signed in to change notification settings - Fork 5
36 lines (29 loc) Β· 1.23 KB
/
pr-issue-close.yml
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
name: Close Issue on PR Merge
on:
pull_request:
types: [closed]
jobs:
close-issue:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Extract issue number from PR body
id: extract_issue
run: |
# Fetch PR body
PR_BODY=$(curl -s -H "Authorization: token ${{ secrets.CONFIG_SUBMODULE_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}" \
| jq -r '.body')
# Extract issue number from PR body using regex (customize if needed)
ISSUE_NUMBER=$(echo "$PR_BODY" | grep -oP '#\d+' | head -1 | sed 's/#//')
echo "ISSUE_NUMBER=$ISSUE_NUMBER" >> $GITHUB_ENV
- name: Close associated issue
if: env.ISSUE_NUMBER != ''
run: |
echo "Closing issue #${{ env.ISSUE_NUMBER }}"
curl -s -X PATCH -H "Authorization: token ${{ secrets.CONFIG_SUBMODULE_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"state": "closed"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/${{ env.ISSUE_NUMBER }}"