From bdb60b0b441b1df791e7bb213b34a81836999b17 Mon Sep 17 00:00:00 2001 From: Real-MullaC Date: Sat, 13 Jul 2024 17:00:37 +0100 Subject: [PATCH] Discussions close on PR merge (#2336) --- .github/PULL_REQUEST_TEMPLATE.md | 2 ++ .github/workflows/close-discussion.yml | 30 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 .github/workflows/close-discussion.yml diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 933ca0e7..30a94605 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -24,6 +24,8 @@ ## Issue related to PR [What issue is related to this PR (if any)] - Resolves # +[What discussion is related to this PR (if any)] +- Discussion: # ## Additional Information [Any additional information that reviewers should be aware of.] diff --git a/.github/workflows/close-discussion.yml b/.github/workflows/close-discussion.yml new file mode 100644 index 00000000..c320a275 --- /dev/null +++ b/.github/workflows/close-discussion.yml @@ -0,0 +1,30 @@ +name: Close Discussion on PR Merge + +on: + pull_request: + types: [closed] + +jobs: + closeDiscussion: + runs-on: ubuntu-latest + steps: + - name: Check if PR was merged + if: github.event.pull_request.merged == true + run: echo "PR was merged" + + - name: Extract Discussion Number + if: github.event.pull_request.merged == true + id: extract-discussion + run: | + echo "::set-output name=discussion::$(echo "${{ github.event.pull_request.body }}" | grep -oP '(?<=Discussion: #)\d+')" + shell: bash + + - name: Close the discussion + if: github.event.pull_request.merged == true && steps.extract-discussion.outputs.discussion + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DISCUSSION_ID: ${{ steps.extract-discussion.outputs.discussion }} + run: | + curl -X PATCH -H "Authorization: token $GITHUB_TOKEN" \ + -d '{"state": "closed"}' \ + "https://api.github.com/repos/${{ github.repository }}/discussions/${DISCUSSION_ID}"