From f4bf4a178c38648872dd4d5051e258e3df244872 Mon Sep 17 00:00:00 2001 From: SinclairLin Date: Mon, 16 Feb 2026 01:03:20 +0800 Subject: [PATCH] ci: auto-delete merged feat and feature branches --- .../auto-delete-feature-branches.yml | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/auto-delete-feature-branches.yml 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}` + });