generated from rerun-io/rerun_template
-
Notifications
You must be signed in to change notification settings - Fork 10
40 lines (36 loc) · 1.58 KB
/
enforce_branch_name.yml
File metadata and controls
40 lines (36 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
name: PR Branch Name Check
on:
pull_request_target:
types: [opened, reopened, synchronize]
permissions:
issues: write
jobs:
check-source-branch:
runs-on: ubuntu-latest
steps:
- name: Check PR source branch
env:
IS_FORK: ${{ github.event.pull_request.head.repo.fork }}
HEAD_REF: ${{ github.event.pull_request.head.ref }}
run: |
# Check if PR is from a fork
if [[ "${IS_FORK}" == "true" ]]; then
# Check if PR is from the master/main branch of a fork
if [[ "${HEAD_REF}" == "master" || "${HEAD_REF}" == "main" ]]; then
echo "ERROR: Pull requests from the master/main branch of forks are not allowed, because it prevents maintainers from contributing to your PR"
echo "Please create a feature branch in your fork and submit the PR from that branch instead."
exit 1
fi
fi
- name: Leave comment if PR is from master/main branch of fork d
if: ${{ failure() }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '⚠️ **ERROR:** Pull requests from the `master`/`main` branch of forks are not allowed, because it prevents maintainers from contributing to your PR. Please create a feature branch in your fork and submit the PR from that branch instead.'
})