diff --git a/.github/workflows/delete-merged-branch.yml b/.github/workflows/delete-merged-branch.yml new file mode 100644 index 0000000..96181c1 --- /dev/null +++ b/.github/workflows/delete-merged-branch.yml @@ -0,0 +1,23 @@ +name: Delete merged branch + +on: + pull_request: + types: + - closed + +jobs: + delete-branch: + if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main' + runs-on: ubuntu-latest + steps: + - name: Delete merged branch + run: | + branch="${{ github.event.pull_request.head.ref }}" + repo="${{ github.repository }}" + token="${{ secrets.GITHUB_TOKEN }}" + if [[ "$branch" != "main" && "$branch" != "master" ]]; then + curl -s -X DELETE \ + -H "Authorization: Bearer $token" \ + -H "Accept: application/vnd.github+json" \ + "https://api.github.com/repos/$repo/git/refs/heads/$branch" + fi