-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
70 lines (70 loc) · 2.75 KB
/
sanitize-closed-issues.yml
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
name: Sanitizes assigned labels and milestone on closed issues
on:
issues:
types:
- closed
permissions: read-all
jobs:
label_issues:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7
with:
script: |
const issue = await github.rest.issues.get({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const originalLabels = issue.data.labels.map(l => l.name);
const newLabels = originalLabels.filter(l => l !== "status: in progress" && l !== "status: new");
if (newLabels.length !== originalLabels.length) {
await github.rest.issues.update({
issue_number: issue.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: newLabels,
});
}
if (issue.data.state_reason === "not_planned") {
if (issue.data.milestone) {
await github.rest.issues.update({
issue_number: issue.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
milestone: null,
});
}
const statusLabels = newLabels.filter(l => l.startsWith("status: "));
if (statusLabels.length === 0) {
await github.rest.issues.createComment({
issue_number: issue.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "Please assign a status label to this issue.",
});
await github.rest.issues.update({
issue_number: issue.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
});
}
} else {
if (!(newLabels.includes("type: task") || newLabels.includes("type: question")) && !issue.data.milestone) {
await github.rest.issues.createComment({
issue_number: issue.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: "Please assign a milestone to this issue or label it with `type: task` or `type: question`.",
});
await github.rest.issues.update({
issue_number: issue.data.number,
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
});
}
}