-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (60 loc) · 2.35 KB
/
delete-workitems.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Delete old workitems
on:
schedule:
- cron: '0 0 1 * *'
workflow_dispatch:
permissions:
contents: read
jobs:
Delete:
name: Delete old workitems
runs-on: ubuntu-latest
steps:
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: '20.x'
- name: Install azure-devops-node-api
run: |
npm install azure-devops-node-api
- name: Delete old workitems
uses: actions/github-script@v7
env:
TOKEN: '${{ secrets.azure_devops_token }}'
ORGANIZATION_URL: 'https://dev.azure.com/EladDeveleap'
with:
script: |
const azureDevOpsApi = require('azure-devops-node-api');
/**
* Deletes work items from Azure DevOps/TFS.
*
* @param {import('azure-devops-node-api/WorkItemTrackingApi').IWorkItemTrackingApi} workItemTrackingApi - The Work Item Tracking API.
* @returns {Promise<void>} - A promise that resolves when the work items are deleted.
*/
async function deleteWorkItem(workItemTrackingApi) {
const wiql = 'SELECT [System.Id] FROM WorkItems';
const result = await workItemTrackingApi.queryByWiql({ query: wiql });
if (result.workItems.length > 0) {
const workItemsId = result.workItems.map(item => item.id);
for (const workItemId of workItemsId) {
await workItemTrackingApi.deleteWorkItem(workItemId, null, true);
console.log(`Deleted workitem ${workItemId}`);
}
}
else {
console.log('No workitems found');
}
}
/**
* Entry point of the script.
*
* @returns {Promise<void>} - A promise that resolves when the script finishes running.
*/
async function run() {
const { TOKEN, ORGANIZATION_URL } = process.env;
const authHandler = azureDevOpsApi.getPersonalAccessTokenHandler(TOKEN);
const connection = new azureDevOpsApi.WebApi(ORGANIZATION_URL, authHandler);
const workItemTrackingApi = await connection.getWorkItemTrackingApi();
await deleteWorkItem(workItemTrackingApi);
}
run();