-
Notifications
You must be signed in to change notification settings - Fork 190
86 lines (74 loc) · 2.8 KB
/
Copy pathissue-version-label.yml
File metadata and controls
86 lines (74 loc) · 2.8 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
name: Issue Version Label
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
on:
issues:
types:
- opened
- edited
jobs:
sync-version-label:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Sync version label from issue form
uses: actions/github-script@v7
with:
script: |
const path = require("path");
const {
getVersionLabelFromIssueBody,
} = require(path.join(process.env.GITHUB_WORKSPACE, ".github/scripts/issue-version-label.js"));
const issue = context.payload.issue;
const currentIssue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
});
const versionLabel = getVersionLabelFromIssueBody(issue.body || "");
const existingVersionLabels = (currentIssue.data.labels || [])
.map((label) => typeof label === "string" ? label : label.name)
.filter((name) => typeof name === "string" && name.startsWith("version:"));
for (const labelName of existingVersionLabels) {
if (labelName === versionLabel) {
continue;
}
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: labelName,
});
}
if (!versionLabel) {
core.info("No version field found in issue body; skipped version label sync.");
return;
}
const existingRepoLabels = await github.paginate(github.rest.issues.listLabelsForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
});
const hasRepoLabel = existingRepoLabels.some((label) => label.name === versionLabel);
if (!hasRepoLabel) {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: versionLabel,
color: "5319e7",
description: "Issues reported against a specific PromptHub version",
});
}
if (!existingVersionLabels.includes(versionLabel)) {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [versionLabel],
});
} else {
core.info(`Version label already up to date: ${versionLabel}`);
}