From 17511de2e363d3b4f6accd10788359832a21aaf7 Mon Sep 17 00:00:00 2001 From: Siddheya Kulkarni <115717746+Asymtode712@users.noreply.github.com> Date: Tue, 21 May 2024 17:21:45 +0530 Subject: [PATCH] created close-on-merge.yml --- .github/workflows/close-on-merge.yml | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/workflows/close-on-merge.yml diff --git a/.github/workflows/close-on-merge.yml b/.github/workflows/close-on-merge.yml new file mode 100644 index 0000000..9a7edc2 --- /dev/null +++ b/.github/workflows/close-on-merge.yml @@ -0,0 +1,30 @@ +name: Close Issues on PR Merge + +on: + pull_request: + types: [closed] + +jobs: + close-issues: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Close linked issues + if: github.event.pull_request.merged == true + run: | + ISSUES=$(jq -r '.pull_request.body' "$GITHUB_EVENT_PATH" | grep -Eo '#[0-9]+' | tr -d '#') + for ISSUE in $ISSUES + do + echo "Closing issue #$ISSUE" + curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE/comments \ + -d '{"body":"Closed by PR #${{ github.event.pull_request.number }}"}' + curl -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + https://api.github.com/repos/${{ github.repository }}/issues/$ISSUE \ + -d '{"state":"closed"}' + done \ No newline at end of file