generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 15
43 lines (37 loc) · 1.24 KB
/
pr-check-block-via-labels.yaml
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
42
43
name: Block mergings PRs if it contains a blocking label (do-not-merge, hold)
on:
pull_request:
types:
- labeled
- unlabeled
- synchronize
- opened
- reopened
permissions:
contents: read
pull-requests: read
checks: write
jobs:
fail-for-labels:
runs-on: ubuntu-latest
steps:
- name: Block if PR has specific labels
uses: actions/github-script@v7
with:
script: |
const pullNumber = context.payload.pull_request.number;
const { data: pullRequest } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: pullNumber,
});
const blockingKeywords = ["do-not-merge", "hold"];
pullRequest.labels.forEach(label =>
blockingKeywords.forEach(blockingKeyword => {
if(label.name.includes(blockingKeyword)) {
console.log(`Blocking merge due to blocking label "${blockingKeyword}"`);
throw new Error('Merging is blocked because this PR contains a blocking label.');
}
})
)
console.log(`No blocking labels found for PR ${pullNumber}`);