From 5dcd363267d9204b07e628c8b975a469c2af0c95 Mon Sep 17 00:00:00 2001 From: oravi Date: Fri, 5 Jul 2024 22:55:36 +0300 Subject: [PATCH] Added close pylon issue workflow --- .github/workflows/close_pylon_issue | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 .github/workflows/close_pylon_issue diff --git a/.github/workflows/close_pylon_issue b/.github/workflows/close_pylon_issue new file mode 100644 index 000000000..7469a77b5 --- /dev/null +++ b/.github/workflows/close_pylon_issue @@ -0,0 +1,41 @@ +name: Close Pylon Ticket on Issue or Pull Request Closure + +on: + issues: + types: [closed] + pull_request: + types: [closed] + +jobs: + close_pylon_ticket: + runs-on: ubuntu-latest + steps: + - name: Check out the repository + uses: actions/checkout@v2 + + - name: Extract Pylon Ticket ID + id: extract_ticket_id + run: | + if [[ "${{ github.event_name }}" == 'issues' ]]; then + ISSUE_BODY=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}" | jq -r '.body') + pylon_ticket_id=$(echo "$ISSUE_BODY" | grep -oP '(?<=)') + elif [[ "${{ github.event_name }}" == 'pull_request' ]]; then + PR_BODY=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" | jq -r '.body') + pylon_ticket_id=$(echo "$PR_BODY" | grep -oP '(?<=)') + fi + echo "::set-output name=pylon_ticket_id::$pylon_ticket_id" + + - name: Close Pylon Ticket + if: steps.extract_ticket_id.outputs.pylon_ticket_id != '' + run: | + pylon_ticket_id=${{ steps.extract_ticket_id.outputs.pylon_ticket_id }} + echo "Closing Pylon Ticket ID: $pylon_ticket_id" + curl --request PATCH \ + --url "https://api.usepylon.com/issues/$pylon_ticket_id" \ + --header "Authorization: ${{ secrets.PYLON_API_KEY }}" \ + --header 'Content-Type: application/json' \ + --data '{ + "state": "closed" + }'