-
Notifications
You must be signed in to change notification settings - Fork 5
124 lines (113 loc) · 4.22 KB
/
Copy pathpull-request.yaml
File metadata and controls
124 lines (113 loc) · 4.22 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
name: Pull Request
on:
pull_request_target:
types:
- opened
- edited
- synchronize
- reopened
permissions:
pull-requests: write
issues: write
jobs:
conventional-commit-labeler:
name: Label PR based on Conventional Commit Specification
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
env:
TYPE_TO_LABEL: |
{
"feat":"kind/feature",
"fix":"kind/bugfix",
"chore":"kind/chore",
"docs":"area/documentation",
"test":"area/testing",
"perf":"area/performance"
}
SCOPE_TO_LABEL: |
{
"deps":"kind/dependency"
}
BREAKING_CHANGE_LABEL: "!BREAKING-CHANGE!"
with:
script: |
console.log("Verify that the PR title follows the Conventional Commit format");
const typeToLabel = JSON.parse(process.env.TYPE_TO_LABEL);
const scopeToLabel = JSON.parse(process.env.SCOPE_TO_LABEL);
const allowedTypes = Object.keys(typeToLabel).join('|');
const prTitle = context.payload.pull_request.title;
console.log(`PR Title: ${prTitle}`);
const regex = new RegExp(
`^(((Initial commit)|(Merge [^\\r\\n]+(\\s)[^\\r\\n]+((\\s)((\\s)[^\\r\\n]+)+)*(\\s)?)|^((?<type>${allowedTypes})(\\((?<scope>[\\w\\-]+)\\))?(?<breaking>!?): (?<subject>[^\\r\\n]+((\\s)((\\s)[^\\r\\n]+)+)*))(\\s)?)$)`
);
const match = prTitle.match(regex);
if (match && match.groups) {
const { type, scope, breaking } = match.groups;
const labels = [];
if (breaking) labels.push(process.env.BREAKING_CHANGE_LABEL);
if (type && typeToLabel[type]) labels.push(typeToLabel[type]);
if (scope && scopeToLabel[scope]) labels.push(scopeToLabel[scope]);
if (labels.length > 0) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: labels,
});
}
} else {
console.log("Invalid PR title format. See https://www.conventionalcommits.org/");
process.exit(1);
}
labeler:
name: Label PR based on Config
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
sparse-checkout: |
.github/config/labeler.yml
- uses: actions/labeler@634933edcd8ababfe52f92936142cc22ac488b1b # v6
with:
configuration-path: .github/config/labeler.yml
size-labeler:
runs-on: ubuntu-latest
name: Label PR based on size
permissions:
issues: write
pull-requests: write
steps:
- uses: codelytv/pr-size-labeler@4ec67706cd878fbc1c8db0a5dcd28b6bb412e85a # v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_label: 'size/xs'
xs_max_size: '10'
s_label: 'size/s'
s_max_size: '100'
m_label: 'size/m'
m_max_size: '500'
l_label: 'size/l'
l_max_size: '10000'
xl_label: 'size/xl'
fail_if_xl: 'false'
message_if_xl: >
This PR exceeds the recommended size of 10000 lines.
Please make sure you are NOT addressing multiple issues with one PR.
Note this PR might be rejected due to its size.
verify-labels:
needs: [labeler, size-labeler, conventional-commit-labeler]
name: verify labels
runs-on: ubuntu-latest
steps:
- name: PRs should have at least one qualifying label
uses: docker://agilepathway/pull-request-label-checker:latest@sha256:14f5f3dfda922496d07d53494e2d2b42885165f90677a1c03d600059b7706a61
with:
any_of: kind/chore,kind/bugfix,kind/feature,kind/dependency,kind/refactor
repo_token: ${{ secrets.GITHUB_TOKEN }}