From 295b7a6a9b4265c7cc17409694ba3e5883a31b51 Mon Sep 17 00:00:00 2001 From: Sayali Gaikawad Date: Wed, 18 Sep 2024 14:06:39 -0700 Subject: [PATCH] Refactor branch deletion for backports Signed-off-by: Sayali Gaikawad --- .github/workflows/delete_backport_branch.yml | 36 ++++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/delete_backport_branch.yml b/.github/workflows/delete_backport_branch.yml index 387a124b8cb6a..67ede6ef5558c 100644 --- a/.github/workflows/delete_backport_branch.yml +++ b/.github/workflows/delete_backport_branch.yml @@ -1,15 +1,23 @@ -name: Delete merged branch of the backport PRs -on: - pull_request: - types: - - closed +--- + name: Delete merged branch of the backport PRs + on: + pull_request: + types: + - closed -jobs: - delete-branch: - runs-on: ubuntu-latest - if: startsWith(github.event.pull_request.head.ref,'backport/') - steps: - - name: Delete merged branch - uses: SvanBoxel/delete-merged-branch@main - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + jobs: + delete-branch: + runs-on: ubuntu-latest + permissions: + contents: write + if: startsWith(github.event.pull_request.head.ref,'backport/') + steps: + - name: Delete branch + uses: actions/github-script@v5 + with: + script: | + github.rest.git.deleteRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `heads/${context.payload.pull_request.head.ref}`, + })