File tree Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Expand file tree Collapse file tree 2 files changed +56
-1
lines changed Original file line number Diff line number Diff line change
1
+ name : Label PR
2
+
3
+ on :
4
+ workflow_call :
5
+ secrets :
6
+ BOT_TOKEN :
7
+ required : true
8
+
9
+ permissions :
10
+ contents : read
11
+ pull-requests : write
12
+
13
+ jobs :
14
+ autolabel :
15
+ runs-on : ubuntu-latest
16
+ name : Automatically Label PR
17
+ if : ${{ !github.event.pull_request.draft && !contains(github.event.pull_request.labels.*.name , 'release') }}
18
+ steps :
19
+
20
+ with :
21
+ github-token : ${{ secrets.BOT_TOKEN }}
22
+ script : |
23
+ const labelPatterns = {
24
+ feature: ["feature/*", "feat/*"],
25
+ fix: "fix/*",
26
+ chore: "chore/*",
27
+ docs: "docs/*",
28
+ refactor: "refactor/*",
29
+ ci: "ci/*"
30
+ };
31
+
32
+ const branchName = context.payload.pull_request.head.ref
33
+ const labelsToAdd = [];
34
+
35
+ for (const label in labelPatterns) {
36
+ const patterns = Array.isArray(labelPatterns[label]) ? labelPatterns[label] : [labelPatterns[label]];
37
+ for (const pattern of patterns) {
38
+ if (branchName.match(new RegExp(`^${pattern.replace('*', '.*')}$`))) {
39
+ labelsToAdd.push(label);
40
+ break;
41
+ }
42
+ }
43
+ }
44
+
45
+ if (labelsToAdd.length > 0) {
46
+ core.info(`ℹ️ Matched the following labels: ${labelsToAdd.join(", ")}`)
47
+
48
+ github.rest.issues.addLabels({
49
+ ...context.repo,
50
+ issue_number: context.payload.pull_request.number,
51
+ labels: labelsToAdd
52
+ })
53
+ } else {
54
+ core.info(`ℹ️ The HEAD ref of this PR does not match any of the specified patterns.`)
55
+ }
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ name: Label, Build & Lint PR
10
10
11
11
jobs :
12
12
autolabel :
13
- uses : Navigraph/workflows/ .github/workflows/autolabel.yml@main
13
+ uses : ./ .github/workflows/autolabel.yml
14
14
secrets : inherit
15
15
16
16
filter :
You can’t perform that action at this time.
0 commit comments