diff --git a/.github/workflows/auto-delete-feature-branches.yml b/.github/workflows/auto-delete-feature-branches.yml new file mode 100644 index 0000000..3492bca --- /dev/null +++ b/.github/workflows/auto-delete-feature-branches.yml @@ -0,0 +1,31 @@ +name: auto-delete-feature-branches + +on: + pull_request: + types: + - closed + +permissions: + contents: write + +jobs: + delete-head-branch: + if: >- + github.event.pull_request.merged == true && + github.event.pull_request.head.repo.full_name == github.repository && + ( + startsWith(github.event.pull_request.head.ref, 'feat/') || + startsWith(github.event.pull_request.head.ref, 'feature/') + ) + runs-on: ubuntu-latest + steps: + - name: Delete merged head branch + uses: actions/github-script@v7 + with: + script: | + const headRef = context.payload.pull_request.head.ref; + await github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `heads/${headRef}` + });