diff --git a/.github/workflows/delete-merged-branch.yml b/.github/workflows/delete-merged-branch.yml index 96181c1..d45e403 100644 --- a/.github/workflows/delete-merged-branch.yml +++ b/.github/workflows/delete-merged-branch.yml @@ -1,20 +1,36 @@ name: Delete merged branch on: - pull_request: - types: - - closed + push: + branches: + - main + +permissions: + contents: write jobs: - delete-branch: - if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' + delete-merged-branch: runs-on: ubuntu-latest steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Get merged PR + id: pr + uses: octokit/request-action@v2.x + with: + route: GET /repos/${{ github.repository }}/commits/${{ github.sha }}/pulls + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Delete merged branch + if: steps.pr.outputs.data != '[]' run: | - branch="${{ github.event.pull_request.head.ref }}" + branch=$(echo '${{ steps.pr.outputs.data }}' | jq -r '.[0].head.ref') repo="${{ github.repository }}" token="${{ secrets.GITHUB_TOKEN }}" + + echo "Deleting branch: $branch" if [[ "$branch" != "main" && "$branch" != "master" ]]; then curl -s -X DELETE \ -H "Authorization: Bearer $token" \