Skip to content

refactor(plugins): reduce type casting in generators #448

refactor(plugins): reduce type casting in generators

refactor(plugins): reduce type casting in generators #448

name: Cleanup Merged Branches
on:
pull_request:
types: [closed]
permissions: {}
jobs:
delete-branch:
# Bot-generated `chore/update-generated-examples-*` branches are excepted from the
# merged-only guard: their PR targets the source PR's own branch (see pr.yml), so when
# that source branch merges or closes first, GitHub auto-closes this PR unmerged and
# the branch would otherwise never get cleaned up.
if: >-
github.event.pull_request.merged == true ||
startsWith(github.event.pull_request.head.ref, 'chore/update-generated-examples-')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Delete merged branch
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9
with:
script: |
const branch = context.payload.pull_request.head.ref;
if (['master', 'next'].includes(branch)) return;
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`,
});
console.log(`Deleted branch: ${branch}`);
} catch (e) {
console.log(`Branch ${branch} already deleted or protected`);
}