-
Notifications
You must be signed in to change notification settings - Fork 479
57 lines (46 loc) · 1.58 KB
/
add-triage-label.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
# Whenever a new issue is opened, this workflow adds the "status: needs triage"
# label, unless the issue already has one of the "Internal" labels.
name: Add Triage Label
on:
issues:
types:
- reopened
- opened
jobs:
add-triage-label:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Run
uses: actions/github-script@v7
with:
script: |
const INTERNAL_LABELS = ["Internal", "status: triaged"];
async function getIssueLabels() {
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
return labels.map(label => label.name);
}
async function issueHasInternalLabels() {
const labels = await getIssueLabels();
return INTERNAL_LABELS.some(item => labels.includes(item));
}
async function addNeedsTriageLabelToIssue() {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["status: needs triage"]
});
}
try {
if (!await issueHasInternalLabels()) {
await addNeedsTriageLabelToIssue();
}
} catch (error) {
core.setFailed(`Error: ${error}`);
}