forked from xevrion-v2/agent-playground
-
Notifications
You must be signed in to change notification settings - Fork 0
88 lines (70 loc) · 2.26 KB
/
Copy pathcreate-labels.yml
File metadata and controls
88 lines (70 loc) · 2.26 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
name: Create Labels
on:
workflow_dispatch:
permissions:
issues: write
jobs:
create-labels:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Create or update labels
uses: actions/github-script@v7
with:
script: |
const fs = require("fs");
const content = fs.readFileSync(".github/labels.yml", "utf8");
const labels = [];
let current = null;
for (const rawLine of content.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line) {
continue;
}
if (line.startsWith("- name:")) {
if (current) {
labels.push(current);
}
current = {
name: line.replace("- name:", "").trim().replace(/^"|"$/g, "")
};
continue;
}
if (!current) {
continue;
}
const separatorIndex = line.indexOf(":");
if (separatorIndex === -1) {
continue;
}
const key = line.slice(0, separatorIndex).trim();
const value = line.slice(separatorIndex + 1).trim().replace(/^"|"$/g, "");
current[key] = value;
}
if (current) {
labels.push(current);
}
for (const label of labels) {
const color = label.color.replace(/^#/, "");
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name,
color,
description: label.description || ""
});
} catch (error) {
if (error.status !== 422) {
throw error;
}
await github.rest.issues.updateLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name,
color,
description: label.description || ""
});
}
}