Skip to content

Commit e3f8dd8

Browse files
authored
Merge pull request #14 from EnderModuBot/maintaince/11-branch-soll-nach-merge-automatisch-gelöscht-werden-end
Ändere Workflow zum Löschen von zusammengeführten Branches, um auf Pu…
2 parents 0c3e491 + 20bbd93 commit e3f8dd8

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

.github/workflows/delete-merged-branch.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
name: Delete merged branch
22

33
on:
4-
pull_request:
5-
types:
6-
- closed
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: write
710

811
jobs:
9-
delete-branch:
10-
if: github.event.pull_request.merged == true && github.event.pull_request.base.ref == 'main'
12+
delete-merged-branch:
1113
runs-on: ubuntu-latest
1214
steps:
15+
- name: Checkout repo
16+
uses: actions/checkout@v4
17+
18+
- name: Get merged PR
19+
id: pr
20+
uses: octokit/request-action@v2.x
21+
with:
22+
route: GET /repos/${{ github.repository }}/commits/${{ github.sha }}/pulls
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
1326
- name: Delete merged branch
27+
if: steps.pr.outputs.data != '[]'
1428
run: |
15-
branch="${{ github.event.pull_request.head.ref }}"
29+
branch=$(echo '${{ steps.pr.outputs.data }}' | jq -r '.[0].head.ref')
1630
repo="${{ github.repository }}"
1731
token="${{ secrets.GITHUB_TOKEN }}"
32+
33+
echo "Deleting branch: $branch"
1834
if [[ "$branch" != "main" && "$branch" != "master" ]]; then
1935
curl -s -X DELETE \
2036
-H "Authorization: Bearer $token" \

0 commit comments

Comments
 (0)