Created
June 13, 2018 18:28
-
-
Save zpv/0d343961118dbd528764f5139f48bb67 to your computer and use it in GitHub Desktop.
[Open Bugs Parented to Closed Stories] Set Work Item Parent to Related and Reparent to Regression Bugs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let vsts = require('vso-node-api'); | |
let collectionURL = 'https://mcfddigitalservices.visualstudio.com/defaultcollection' | |
let workItemURL = 'https://mcfddigitalservices.visualstudio.com/_apis/wit/workItems/' | |
let token = 'TOKEN_HERE' | |
let authHandler = vsts.getPersonalAccessTokenHandler(token); | |
let connect = new vsts.WebApi(collectionURL, authHandler); | |
// ID of Regression Bugs Parent User Story | |
const regressionBugsUSId = 6294; | |
async function run() { | |
let project = 'MCFD Digital Services'; | |
let vstsWorkTracking = await connect.getWorkItemTrackingApi(); | |
// Run Patrick's Bugs to Closed Stories Query | |
let queryResults = await vstsWorkTracking.queryById("efea8964-582d-45cd-8a85-0346746bff62", {project: project}) | |
// Filter for linked bugs | |
let linkedBugs = queryResults.workItemRelations.filter((item) =>{ | |
return item.rel == 'System.LinkTypes.Hierarchy-Reverse' && item.source != null && item.target != null; | |
}) | |
for(let link of linkedBugs){ | |
let bugId = link.source.id | |
let parentId = link.target.id | |
let workItem = await vstsWorkTracking.getWorkItem(bugId, null,null, 'Relations') | |
// Find index of parented story | |
let relation = workItem.relations.findIndex((relation) => { | |
return relation.rel == 'System.LinkTypes.Hierarchy-Reverse' && relation.url.includes('/workItems/' + parentId) | |
}) | |
if (relation != -1) { | |
// Remove parent story and make it related, add Regression Bug user story as parent | |
let request = [ | |
{ | |
'op': 'remove', | |
'path': '/relations/' + relation | |
},{ | |
'op': 'add', | |
'path': '/relations/-', | |
'value': { | |
'rel': 'System.LinkTypes.Related', | |
'url': workItemURL + parentId | |
} | |
},{ | |
'op': 'add', | |
'path': '/relations/-', | |
'value': { | |
'rel': 'System.LinkTypes.Hierarchy-Reverse', | |
'url': workItemURL + regressionBugsUSId, | |
'attributes': { | |
'comment': 'Automated parenting to Regression User Story' | |
} | |
} | |
} | |
] | |
let updated = await vstsWorkTracking.updateWorkItem(null, request, bugId) | |
console.log('Updated sucessfully: #' + bugId) | |
} | |
} | |
} | |
run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment