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

Fix issues with the tag workflow #4458

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
38 changes: 33 additions & 5 deletions .github/workflows/tagPriorityLow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ name: tag low priority issues

on:
workflow_dispatch:
schedule:
- cron: '0 16 * * 4'

permissions:
issues: write
Expand Down Expand Up @@ -37,15 +39,27 @@ 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) {

// 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) {
Expand All @@ -54,7 +68,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];
}
Expand All @@ -67,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) => {
Expand Down
Loading