Skip to content

Commit

Permalink
Simplified branch protection workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hugoabernier authored Oct 28, 2024
1 parent 5976b96 commit b983184
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/branch-protection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ on:
pull_request:
types: [opened, synchronize]

permissions:
pull-requests: write # Allows commenting on and closing PRs

jobs:
prevent_merge:
runs-on: ubuntu-latest
steps:
- name: Check branch names
- name: Comment and Close PR if merging from sic-main to main
if: github.event.pull_request.base.ref == 'main' && github.event.pull_request.head.ref == 'sic-main'
run: |
# Post a comment on the PR
curl -s -X POST -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"body": "Merging from `sic-main` to `main` is not allowed. This pull request will be automatically closed."}' \
"${{ github.event.pull_request.url }}/comments"
-d '{"body": "Pull requests from `sic-main` to `main` are not allowed. This PR will be closed automatically."}' \
"${{ github.event.pull_request.comments_url }}"
# Close the PR
curl -s -X PATCH -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d '{"state": "closed"}' \
"${{ github.event.pull_request.url }}"
env:
PR_SOURCE_BRANCH: ${{ github.event.pull_request.head.ref }}
PR_TARGET_BRANCH: ${{ github.event.pull_request.base.ref }}

0 comments on commit b983184

Please sign in to comment.