From 3694e2fe54237abd8fafb11b325547138a2f7530 Mon Sep 17 00:00:00 2001 From: zeme Date: Mon, 20 May 2024 12:21:35 +0200 Subject: [PATCH 1/3] Add triage label only when the issue does not have any of the 'Internal' labels --- .github/workflows/add-triage-label.yml | 43 +++++++++++++++++++++----- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/.github/workflows/add-triage-label.yml b/.github/workflows/add-triage-label.yml index 963b4a3ba56..0d687f1c0e5 100644 --- a/.github/workflows/add-triage-label.yml +++ b/.github/workflows/add-triage-label.yml @@ -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 @@ -13,10 +17,35 @@ 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"] - }) \ No newline at end of file + script: | + const INTERNAL_LABELS = ["Internal"]; + + 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"] + }); + } + + if (!await issueHasInternalLabels()) { + async addNeedsTriageLabelToIssue(); + } + + + \ No newline at end of file From ff9d45817b1bdb2f627fe716d8e51e703230802d Mon Sep 17 00:00:00 2001 From: zeme Date: Mon, 20 May 2024 12:25:15 +0200 Subject: [PATCH 2/3] wip --- .github/workflows/add-triage-label.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/add-triage-label.yml b/.github/workflows/add-triage-label.yml index 0d687f1c0e5..1a2ae6fea8d 100644 --- a/.github/workflows/add-triage-label.yml +++ b/.github/workflows/add-triage-label.yml @@ -43,9 +43,15 @@ jobs: }); } - if (!await issueHasInternalLabels()) { - async addNeedsTriageLabelToIssue(); - } + try { + if (!await issueHasInternalLabels()) { + await addNeedsTriageLabelToIssue(); + } + } catch (error) { + core.setFailed(`Error: ${error}`); + } + + \ No newline at end of file From 08724294060cdb87d6b940ddbc091f964a534d25 Mon Sep 17 00:00:00 2001 From: zeme Date: Mon, 20 May 2024 13:16:28 +0200 Subject: [PATCH 3/3] wip --- .github/workflows/add-triage-label.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/add-triage-label.yml b/.github/workflows/add-triage-label.yml index 1a2ae6fea8d..383435d1ce4 100644 --- a/.github/workflows/add-triage-label.yml +++ b/.github/workflows/add-triage-label.yml @@ -18,7 +18,7 @@ jobs: uses: actions/github-script@v7 with: script: | - const INTERNAL_LABELS = ["Internal"]; + const INTERNAL_LABELS = ["Internal", "status: triaged"]; async function getIssueLabels() { const { data: labels } = await github.issues.listLabelsOnIssue({