test new issue #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
}); |