Skip to content

Commit

Permalink
Conditionally add 'triage' label to new issues (#6061)
Browse files Browse the repository at this point in the history
* Add triage label only when the issue does not have any of the 'Internal' labels
  • Loading branch information
zeme-wana authored May 21, 2024
1 parent 9326493 commit ef97537
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions .github/workflows/add-triage-label.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# Whenever a new issue is opened, this workflow adds the "status: needs triage"
# label, unless the issue already has one of the "Internal" labels.

name: Add Triage Label
on:
issues:
types:
- reopened
- opened

jobs:
add-triage-label:
runs-on: ubuntu-latest
Expand All @@ -13,10 +17,41 @@ jobs:
- name: Run
uses: actions/github-script@v7
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["status: needs triage"]
})
script: |
const INTERNAL_LABELS = ["Internal", "status: triaged"];
async function getIssueLabels() {
const { data: labels } = await github.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
return labels.map(label => label.name);
}
async function issueHasInternalLabels() {
const labels = await getIssueLabels();
return INTERNAL_LABELS.some(item => labels.includes(item));
}
async function addNeedsTriageLabelToIssue() {
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["status: needs triage"]
});
}
try {
if (!await issueHasInternalLabels()) {
await addNeedsTriageLabelToIssue();
}
} catch (error) {
core.setFailed(`Error: ${error}`);
}

0 comments on commit ef97537

Please sign in to comment.