Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditionally add 'triage' label to new issues #6061

Merged
merged 3 commits into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}`);
}