From b28881a893b136881e94133e77e023c8fec28c6f Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Tue, 26 Mar 2024 15:48:38 -0700 Subject: [PATCH 1/5] fix bunch issue --- .github/workflows/tagPriorityLow.yml | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tagPriorityLow.yml b/.github/workflows/tagPriorityLow.yml index 69fa4e862..4362006a6 100644 --- a/.github/workflows/tagPriorityLow.yml +++ b/.github/workflows/tagPriorityLow.yml @@ -37,13 +37,26 @@ jobs: // Querying Lastest Work Items const queryResult = await adoClient.queryById(process.env.query_id); - // Iterate over work items, including relations - // https://github.com/microsoft/azure-devops-node-api/blob/master/api/interfaces/WorkItemTrackingInterfaces.ts#L1485 - const workItemsDetails = await adoClient.getWorkItems(queryResult.workItems.map(wi => wi.id), null, null, 1); + // Work Item IDs + const workItemIds = queryResult.workItems.map(wi => wi.id); + + // getWorkItems has a limit of 200, so we need to batch the requests + const batchSize = 200; + const workItemsDetails = []; + + for (let i = 0; i < workItemIds.length; i += batchSize) { + const batchIds = workItemIds.slice(i, i + batchSize); + // Include relations in the response + // https://github.com/microsoft/azure-devops-node-api/blob/master/api/interfaces/WorkItemTrackingInterfaces.ts#L1485 + const batchDetails = await adoClient.getWorkItems(batchIds, null, null, 1); + workItemsDetails.push(...batchDetails); + } // Obtain GitHub Issue Number function getGitHubIssueNumber(workItem) { + console.log(workItem); + // Try using relations const relation = workItem.relations.find(r => r.rel === 'Hyperlink' && r.url.includes('github.com')); if (relation) { From 2f591c84d6a788522e9a5cb650ff94af17463f78 Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Tue, 26 Mar 2024 15:52:33 -0700 Subject: [PATCH 2/5] Add null chaining --- .github/workflows/tagPriorityLow.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tagPriorityLow.yml b/.github/workflows/tagPriorityLow.yml index 4362006a6..9bc169107 100644 --- a/.github/workflows/tagPriorityLow.yml +++ b/.github/workflows/tagPriorityLow.yml @@ -55,10 +55,9 @@ jobs: // Obtain GitHub Issue Number function getGitHubIssueNumber(workItem) { - console.log(workItem); - // Try using relations - const relation = workItem.relations.find(r => r.rel === 'Hyperlink' && r.url.includes('github.com')); + const relation = workItem?.relations?.find(r => r.rel === 'Hyperlink' && r.url.includes('github.com')); + if (relation) { const match = relation.url.match(/github.com\/[^/]+\/[^/]+\/issues\/(\d+)/); if (match) { From 564a617fbc4c1ef901eb16dedd68dd92cffaa63a Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Tue, 26 Mar 2024 15:53:00 -0700 Subject: [PATCH 3/5] Add another null chain --- .github/workflows/tagPriorityLow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tagPriorityLow.yml b/.github/workflows/tagPriorityLow.yml index 9bc169107..825e7f8a1 100644 --- a/.github/workflows/tagPriorityLow.yml +++ b/.github/workflows/tagPriorityLow.yml @@ -66,7 +66,7 @@ jobs: } // Try using the title, which includes [GitHub #123] - const match = workItem.fields['System.Title'].match(/\[GitHub #(\d+)\]/); + const match = workItem?.fields['System.Title']?.match(/\[GitHub #(\d+)\]/); if (match) { return match[1]; } From 2288d2b84a712e86033bc13d0f8b37f1bc623ddb Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Mon, 1 Apr 2024 15:06:18 -0700 Subject: [PATCH 4/5] Add cron schedule to run at 9am every Thursday (PST) --- .github/workflows/tagPriorityLow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/tagPriorityLow.yml b/.github/workflows/tagPriorityLow.yml index 825e7f8a1..6ce1c7f21 100644 --- a/.github/workflows/tagPriorityLow.yml +++ b/.github/workflows/tagPriorityLow.yml @@ -2,6 +2,8 @@ name: tag low priority issues on: workflow_dispatch: + schedule: + - cron: '0 16 * * 4' permissions: issues: write From 12c033bce32236abc17af19eebc39d0f99d9d086 Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Thu, 23 May 2024 14:21:07 -0700 Subject: [PATCH 5/5] don't add label if it already exists --- .github/workflows/tagPriorityLow.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/tagPriorityLow.yml b/.github/workflows/tagPriorityLow.yml index 6ce1c7f21..0d79cf92a 100644 --- a/.github/workflows/tagPriorityLow.yml +++ b/.github/workflows/tagPriorityLow.yml @@ -81,12 +81,26 @@ jobs: // Add priority-low label to GitHub issues const addLowPriorityLabel = async (issueNumber) => { + // Check if the issue already has the label + const { data: labels } = await github.rest.issues.listLabelsOnIssue({ + issue_number: issueNumber, + owner: context.repo.owner, + repo: context.repo.repo + }); + + if (labels.some(l => l.name === 'priority-low')) { + console.log(`Issue #${issueNumber} already has the label`); + return; + } + + // Add the label await github.rest.issues.addLabels({ issue_number: issueNumber, owner: context.repo.owner, repo: context.repo.repo, labels: ['priority-low'] }); + console.log(`Added label to issue #${issueNumber}`); } ghIssueNumbers.forEach(async (issueNumber) => {