diff --git a/src/WorkItemUpdater.ts b/src/WorkItemUpdater.ts index 2bab95d..0ce8c4c 100644 --- a/src/WorkItemUpdater.ts +++ b/src/WorkItemUpdater.ts @@ -184,53 +184,31 @@ async function getWorkItemsRefs(vstsWebApi: WebApi, workItemTrackingClient: IWor } async function getBuildOrReleaseWorkItemsRefs(vstsWebApi: WebApi, settings: Settings): Promise { - const buildClient: IBuildApi = await vstsWebApi.getBuildApi(); - let workItemRefs: ResourceRef[] = []; - - if (settings.releaseId) { + if (settings.releaseId && settings.allWorkItemsSinceLastRelease) { console.log('Using Release as WorkItem Source'); const releaseClient: IReleaseApi = await vstsWebApi.getReleaseApi(); - const currentRelease = await releaseClient.getRelease(settings.projectId, settings.releaseId); - - const baseDeployments = await releaseClient.getDeployments(settings.projectId, settings.definitionId, settings.definitionEnvironmentId, undefined, undefined, undefined, DeploymentStatus.Succeeded, undefined, undefined, ReleaseQueryOrder.Descending, 1); - if (baseDeployments.length > 0 && settings.allWorkItemsSinceLastRelease) { - const baseReleaseId = Number(baseDeployments[0].release.id); + const deployments = await releaseClient.getDeployments(settings.projectId, settings.definitionId, settings.definitionEnvironmentId, undefined, undefined, undefined, DeploymentStatus.Succeeded, undefined, undefined, ReleaseQueryOrder.Descending, 1); + if (deployments.length > 0) { + const baseReleaseId = deployments[0].release.id; tl.debug('Using Release ' + baseReleaseId + ' as BaseRelease for ' + settings.releaseId); - - const baseRelease = await releaseClient.getRelease(settings.projectId, baseReleaseId); - - for (const currentArtifact of currentRelease.artifacts) { - const baseArtifact = baseRelease.artifacts.find((artifact) => { return artifact.sourceId === currentArtifact.sourceId; }); - - const releaseWorkItemRefs = await buildClient.getWorkItemsBetweenBuilds(settings.projectId, Number(baseArtifact.definitionReference.version.id), Number(currentArtifact.definitionReference.version.id), settings.workitemLimit); - pushWorkItemsRefs(workItemRefs, releaseWorkItemRefs); - } - } else { - for (const currentArtifact of currentRelease.artifacts) { - const releaseWorkItemRefs = await buildClient.getBuildWorkItemsRefs(settings.projectId, Number(currentArtifact.definitionReference.version.id), settings.workitemLimit); - pushWorkItemsRefs(workItemRefs, releaseWorkItemRefs); - } + const releaseWorkItemRefs = await releaseClient.getReleaseWorkItemsRefs(settings.projectId, settings.releaseId, baseReleaseId); + const result: ResourceRef[] = []; + releaseWorkItemRefs.forEach((releaseWorkItem) => { + result.push({ + id: releaseWorkItem.id.toString(), + url: releaseWorkItem.url + }); + }); + return result; } - return workItemRefs; } console.log('Using Build as WorkItem Source'); - workItemRefs = await buildClient.getBuildWorkItemsRefs(settings.projectId, settings.buildId, settings.workitemLimit); + const buildClient: IBuildApi = await vstsWebApi.getBuildApi(); + const workItemRefs: ResourceRef[] = await buildClient.getBuildWorkItemsRefs(settings.projectId, settings.buildId, settings.workitemLimit); return workItemRefs; } -function pushWorkItemsRefs(workItemRefs: ResourceRef[], workItemRefsToAdd: ResourceRef[]) { - if (typeof workItemRefsToAdd == "undefined") { - workItemRefsToAdd = []; - } - workItemRefsToAdd.forEach((workItemRef: ResourceRef) => { - workItemRefs.push({ - id: workItemRef.id.toString(), - url: workItemRef.url - }); - }); -} - async function getQueryWorkItemsRefs(workItemTrackingClient: IWorkItemTrackingApi, settings: Settings): Promise { console.log('Using Query as WorkItem Source'); const result: ResourceRef[] = [];