Skip to content

Commit

Permalink
auto labels
Browse files Browse the repository at this point in the history
  • Loading branch information
jpmens committed Feb 10, 2024
1 parent 24124d2 commit 84901e3
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# invented by @simonw
# via https://github.com/simonw/create-labels-workflow/blob/main/.github/workflows/labels.yml
name: Update repository labels

on:
push:
branches:
- main
paths:
- '.github/workflows/labels.yml'

jobs:
create-labels:
runs-on: ubuntu-latest
permissions:
issues: write
env:
LABELS_JSON: |
[
{"name": "research", "color": "ededed", "description": "Research needed"},
{"name": "ops", "color": "c2e0c6", "description": "Ops task"},
{"name": "demo", "color": "bfdadc", "description": "Demo label"}
]
steps:
- uses: actions/github-script@v7
with:
script: |
const labels = JSON.parse(process.env.LABELS_JSON);
for (const label of labels) {
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name: label.name,
description: label.description || '',
color: label.color
});
} catch (error) {
// Check if the error is because the label already exists
if (error.status === 422) {
console.log(`Label '${label.name}' already exists. Skipping.`);
} else {
// Log other errors
console.error(`Error creating label '${label.name}': ${error}`);
}
}
}

0 comments on commit 84901e3

Please sign in to comment.