-
Notifications
You must be signed in to change notification settings - Fork 3
93 lines (76 loc) · 2.49 KB
/
Copy pathLABEL.yml
File metadata and controls
93 lines (76 loc) · 2.49 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
name: Auto label Pull requests
on:
pull_request:
types:
- opened
- reopened
- edited
concurrency:
group: build-${{ github.event.pull_request.number || github.head_ref }}
cancel-in-progress: true
jobs:
label:
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- name: Assign label
uses: actions/github-script@v7
with:
script: |
const title = context.payload.pull_request.title.toLowerCase();
let label = null;
if (
title.startsWith("fix") ||
title.startsWith("bug") ||
title.startsWith("patch")
) {label = "patch";}
else if (
title.startsWith("feat") ||
title.startsWith("feature") ||
title.startsWith("add")
) {label = "feature";}
else if (
title.startsWith("build") ||
title.startsWith("pkg") ||
title.startsWith("docs") ||
title.startsWith("github") ||
title.startsWith("gh")
) {label = "build";}
if (!label) {
console.log("No matching label for title:", title);
return;
}
const issue_number = context.issue.number;
// fetch current labels
const issue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number
});
const versionLabels = ["feature", "patch", "build"];
// remove old version labels
for (const existing of issue.data.labels.map(l => l.name)) {
if (!versionLabels.includes(existing)) continue;
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
name: existing
});
}
// apply new label
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
labels: [label]
});
// feedback
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
body: `✅ Version label set to **${label}**`
});