|
1 |
| -name: update low priority items based on ADO query |
| 1 | +name: tag low priority issues |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | workflow_dispatch:
|
5 | 5 |
|
| 6 | +permissions: |
| 7 | + issues: write |
| 8 | + |
6 | 9 | jobs:
|
7 |
| - update-low-priority-items: |
| 10 | + tag-low-priority-issues: |
8 | 11 | runs-on: ubuntu-latest
|
9 | 12 | steps:
|
10 |
| - - uses: actions/setup-node@v3 |
| 13 | + - uses: actions/setup-node@v4 |
11 | 14 | with:
|
12 | 15 | node-version: '20.x'
|
13 | 16 | - run: npm install azure-devops-node-api
|
14 | 17 | - uses: actions/github-script@v7
|
15 | 18 | env:
|
16 | 19 | ado_token: '${{ secrets.ADO_PERSONAL_ACCESS_TOKEN }}'
|
17 |
| - query_id: '${{ secrets.ADO_QUERY_ID }}' |
| 20 | + query_id: '6777cf01-7065-42ca-99ca-ba0d7b77d8fd' |
18 | 21 | with:
|
19 | 22 | script: |
|
20 | 23 | const azdev = require('azure-devops-node-api')
|
21 |
| - |
| 24 | +
|
| 25 | + // Get the ADO client |
22 | 26 | try {
|
23 | 27 | const orgUrl = "https://dev.azure.com/microsoft";
|
24 | 28 | const adoAuthHandler = azdev.getPersonalAccessTokenHandler(process.env.ado_token);
|
|
30 | 34 | return;
|
31 | 35 | }
|
32 | 36 |
|
| 37 | + // Querying Lastest Work Items |
33 | 38 | const queryResult = await adoClient.queryById(process.env.query_id);
|
34 |
| - console.log(queryResult); |
| 39 | + |
| 40 | + // Iterate over work items, including relations |
| 41 | + // https://github.com/microsoft/azure-devops-node-api/blob/master/api/interfaces/WorkItemTrackingInterfaces.ts#L1485 |
| 42 | + const workItemsDetails = await adoClient.getWorkItems(queryResult.workItems.map(wi => wi.id), null, null, 1); |
| 43 | + |
| 44 | + // Obtain GitHub Issue Number |
| 45 | + function getGitHubIssueNumber(workItem) { |
| 46 | +
|
| 47 | + // Try using relations |
| 48 | + const relation = workItem.relations.find(r => r.rel === 'Hyperlink' && r.url.includes('github.com')); |
| 49 | + if (relation) { |
| 50 | + const match = relation.url.match(/github.com\/[^/]+\/[^/]+\/issues\/(\d+)/); |
| 51 | + if (match) { |
| 52 | + return match[1]; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + // Try using the title, which includes [GitHub #123] |
| 57 | + const match = workItem.fields['System.Title'].match(/\[GitHub #(\d+)\]/); |
| 58 | + if (match) { |
| 59 | + return match[1]; |
| 60 | + } |
| 61 | +
|
| 62 | + return null; |
| 63 | + } |
| 64 | + |
| 65 | + // Map ADO work items to GitHub number, remove nulls |
| 66 | + const ghIssueNumbers = workItemsDetails.map(wi => getGitHubIssueNumber(wi)).filter(n => n !== null); |
| 67 | + |
| 68 | + // Add priority-low label to GitHub issues |
| 69 | + const addLowPriorityLabel = async (issueNumber) => { |
| 70 | + await github.rest.issues.addLabels({ |
| 71 | + issue_number: issueNumber, |
| 72 | + owner: context.repo.owner, |
| 73 | + repo: context.repo.repo, |
| 74 | + labels: ['priority-low'] |
| 75 | + }); |
| 76 | + } |
| 77 | + |
| 78 | + ghIssueNumbers.forEach(async (issueNumber) => { |
| 79 | + await addLowPriorityLabel(issueNumber); |
| 80 | + }); |
| 81 | + |
| 82 | + core.setOutput('Tagged Issues', ghIssueNumbers.join(',')); |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
0 commit comments