-
-
Notifications
You must be signed in to change notification settings - Fork 389
41 lines (36 loc) · 1.3 KB
/
pr-target.yml
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
41
name: "Validate PR target"
on:
pull_request:
types:
- opened
- edited
- synchronize
permissions:
pull-requests: write
jobs:
main:
name: Validate PR target branch
runs-on: ubuntu-latest
steps:
- name: Check PR target
id: check-pr-target
uses: actions/github-script@v7
with:
script: |
const isFeature = context.payload.pull_request.title.startsWith('feat');
const targetsMain = context.payload.pull_request.base.ref == 'main';
core.setOutput('needs-rebase', isFeature && targetsMain ? 'true' : 'false');
- name: Comment PR
if: steps.check-pr-target.outputs.needs-rebase == 'true'
uses: thollander/actions-comment-pull-request@v2
with:
message: "It looks like you are adding a new feature! :rocket: Please rebase and point your PR to the `develop` branch."
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
comment_tag: check_pr_target
mode: recreate
- name: Fail if feature PR is targeted to main
if: steps.check-pr-target.outputs.needs-rebase == 'true'
uses: actions/github-script@v7
with:
script: |
core.setFailed('Cannot merge feature type PR into main. Merge into a feature branch or develop')