Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions .github/workflows/delete-merged-branch.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
name: Delete merged branch

on:
pull_request:
types:
- closed
push:
branches:
- main

permissions:
contents: write

jobs:
delete-branch:
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
delete-merged-branch:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Get merged PR
id: pr
uses: octokit/request-action@v2.x
with:
route: GET /repos/${{ github.repository }}/commits/${{ github.sha }}/pulls
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Delete merged branch
if: steps.pr.outputs.data != '[]'
run: |
branch="${{ github.event.pull_request.head.ref }}"
branch=$(echo '${{ steps.pr.outputs.data }}' | jq -r '.[0].head.ref')
repo="${{ github.repository }}"
token="${{ secrets.GITHUB_TOKEN }}"

echo "Deleting branch: $branch"
if [[ "$branch" != "main" && "$branch" != "master" ]]; then
curl -s -X DELETE \
-H "Authorization: Bearer $token" \
Expand Down
Loading