-
Notifications
You must be signed in to change notification settings - Fork 0
68 lines (66 loc) · 2.08 KB
/
labels.yaml
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
name: Labels
on:
push:
branches:
- deploy
permissions:
issues: write
jobs:
update-labels:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Remove existing labels
uses: actions/github-script@v7
with:
script: |
const {owner, repo} = context.repo;
while (true) {
const labels = (await github.request("GET /repos/{owner}/{repo}/labels", {
owner,
repo,
headers: {
"X-GitHub-Api-Version": "2022-11-28"
}
})).data;
if (!Array.isArray(labels)) {
throw Error("Expected an array");
}
if (labels.length === 0) {
break;
}
for (const label of labels) {
const name = label.name;
console.log(`Deleting label: ${name}`);
await github.request("DELETE /repos/{owner}/{repo}/labels/{name}", {
owner,
repo,
name,
headers: {
"X-GitHub-Api-Version": "2022-11-28"
}
});
}
}
- name: Create new labels
uses: actions/github-script@v7
with:
script: |
const {owner, repo} = context.repo;
const {colors, labels} = require("./labels.json");
for (const label of labels) {
const {description, name} = label;
const color = label.color || Object.entries(colors).find(c => new RegExp(c[0]).test(name))[1];
console.log(`Creating label: ${name}; color = ${color}; description = ${description}`);
await github.request("POST /repos/{owner}/{repo}/labels", {
owner,
repo,
name,
description,
color,
headers: {
"X-GitHub-Api-Version": "2022-11-28"
}
});
}