From eb5d9ce8bdcf90787ab2a6cfc69eda8902b0b187 Mon Sep 17 00:00:00 2001 From: Arachne <66822642+Arachneee@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:20:00 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20pr=20issue=20close=20workflow=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1=20(#328)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pr-issue-close.yml | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/pr-issue-close.yml diff --git a/.github/workflows/pr-issue-close.yml b/.github/workflows/pr-issue-close.yml new file mode 100644 index 000000000..c37eb255d --- /dev/null +++ b/.github/workflows/pr-issue-close.yml @@ -0,0 +1,33 @@ +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 }}"