Repository navigation
chore: bump scip_ruby_version for 0.5.0 release #5
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Delete PR branch | |
| on: | |
| pull_request: | |
| types: [closed] | |
| permissions: | |
| contents: write | |
| jobs: | |
| delete-branch: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Delete branches ending with the PR number | |
| uses: actions/github-script@v8 | |
| with: | |
| script: | | |
| if (context.repo.owner != 'sorbet' || context.repo.repo != 'sorbet') { | |
| return; | |
| } | |
| const suffix = `-${context.payload.pull_request.number}`; | |
| const branches = await github.paginate( | |
| github.rest.repos.listBranches, | |
| { | |
| owner: 'sorbet', | |
| repo: 'sorbet', | |
| per_page: 100, | |
| }, | |
| ); | |
| const matches = branches.filter(({name}) => name.endsWith(suffix)); | |
| if (matches.length === 0) { | |
| core.info(`No branches end with ${suffix}`); | |
| return; | |
| } | |
| for (const {name} of matches) { | |
| try { | |
| await github.rest.git.deleteRef({ | |
| owner: 'sorbet', | |
| repo: 'sorbet', | |
| ref: `heads/${name}`, | |
| }); | |
| core.info(`Deleted branch ${name}`); | |
| } catch (error) { | |
| if (error.status === 422) { | |
| core.warning(`Branch ${name} no longer exists or cannot be deleted`); | |
| } else { | |
| throw error; | |
| } | |
| } | |
| } |