-
Notifications
You must be signed in to change notification settings - Fork 3
91 lines (74 loc) · 2.61 KB
/
Copy pathCOMMENTS.yml
File metadata and controls
91 lines (74 loc) · 2.61 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
name: Automatic comments
on:
issue_comment:
types: [created]
permissions:
issues: write
pull-requests: write
jobs:
version-label:
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
with:
script: |
const body = context.payload.comment.body.trim().toLowerCase();
const command = body.replace(/^\\/, "");
const mapping = {
feature: "feature",
patch: "patch",
build: "build"
};
const label = mapping[command];
if (!label) return;
const user = context.payload.comment.user.login;
const perm = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: user
});
if (!["admin", "write"].includes(perm.data.permission)) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: "❌ You don't have permission to change version labels."
});
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;
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
name: existing
});
} catch (e) {
console.log(`Could not remove label: ${existing}`, e.message);
}
}
// 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}**`
});