-
Notifications
You must be signed in to change notification settings - Fork 3
81 lines (72 loc) · 2.68 KB
/
auto-assign-date-label.yml
File metadata and controls
81 lines (72 loc) · 2.68 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
name: Monthly Issue Labeler
on:
issues:
types: [opened]
jobs:
label-issue:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Add month-year label
uses: actions/github-script@v7
with:
script: |
const date = new Date();
const monthNames = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
const month = monthNames[date.getMonth()];
const year = date.getFullYear();
const labelName = `${month} ${year}`;
console.log(`Creating/applying label: ${labelName}`);
// Define a set of 12 standard colors (no black or white)
const standardColors = [
"e11d21", // Red
"fbca04", // Yellow
"009800", // Green
"006b75", // Teal
"207de5", // Blue
"0052cc", // Dark Blue
"5319e7", // Purple
"d93f0b", // Orange
"fbad50", // Light Orange
"fc6399", // Pink
"c5def5", // Light Blue
"bfdadc" // Pale Teal
];
// Function to get a color from the standard colors
function getStandardColor() {
const randomIndex = Math.floor(Math.random() * standardColors.length);
return standardColors[randomIndex];
}
// Check if the label exists, create it if it doesn't
try {
await github.rest.issues.getLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: labelName
});
console.log(`Label ${labelName} already exists`);
} catch (error) {
if (error.status === 404) {
const selectedColor = getStandardColor();
console.log(`Creating new label: ${labelName} with color #${selectedColor}`);
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: labelName,
color: selectedColor
});
} else {
throw error;
}
}
// Apply the label to the issue
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: [labelName]
});