Skip to content

Commit 14682eb

Browse files
committed
apply labels
1 parent b11af10 commit 14682eb

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

.github/workflows/update-low-priority.yml

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,48 @@ jobs:
3434
// Querying Lastest Work Items
3535
const queryResult = await adoClient.queryById(process.env.query_id);
3636
37-
// Iterate over work items
37+
// Iterate over work items, including relations
38+
// https://github.com/microsoft/azure-devops-node-api/blob/master/api/interfaces/WorkItemTrackingInterfaces.ts#L1485
3839
const workItemsDetails = await adoClient.getWorkItems(queryResult.workItems.map(wi => wi.id), null, null, 1);
3940
4041
// Obtain GitHub Issue Number
4142
function getGitHubIssueNumber(workItem) {
43+
44+
// Try using relations
4245
const relation = workItem.relations.find(r => r.rel === 'Hyperlink' && r.url.includes('github.com'));
4346
if (relation) {
4447
const match = relation.url.match(/github.com\/[^/]+\/[^/]+\/issues\/(\d+)/);
4548
if (match) {
4649
return match[1];
4750
}
4851
}
52+
53+
// Try using the title, which includes [GitHub #123]
54+
const match = workItem.fields['System.Title'].match(/\[GitHub #(\d+)\]/);
55+
if (match) {
56+
return match[1];
57+
}
58+
4959
return null;
5060
}
51-
52-
// Map ADO work items to GitHub number
53-
const ghIssueNumbers = workItemsDetails.map(wi => getGitHubIssueNumber(wi));
54-
console.log(ghIssueNumbers);
61+
62+
// Map ADO work items to GitHub number, remove nulls
63+
const ghIssueNumbers = workItemsDetails.map(wi => getGitHubIssueNumber(wi)).filter(n => n !== null);
64+
65+
// Add priority-low label to GitHub issues
66+
const addLowPriorityLabel = async (issueNumber) => {
67+
await github.rest.issues.addLabels({
68+
issue_number: issueNumber,
69+
owner: context.repo.owner,
70+
repo: context.repo.repo,
71+
labels: ['priority-low']
72+
});
73+
}
74+
75+
ghIssueNumbers.forEach(async (issueNumber) => {
76+
await addLowPriorityLabel(issueNumber);
77+
});
78+
79+
5580

5681

0 commit comments

Comments
 (0)