Skip to content

Commit

Permalink
Merge pull request #152 from BlueBasher/Revert-PR62
Browse files Browse the repository at this point in the history
Revert PR 62
  • Loading branch information
BlueBasher authored Aug 23, 2024
2 parents 87e8efb + 9d0b67b commit 8d258ef
Showing 1 changed file with 15 additions and 37 deletions.
52 changes: 15 additions & 37 deletions src/WorkItemUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,53 +184,31 @@ async function getWorkItemsRefs(vstsWebApi: WebApi, workItemTrackingClient: IWor
}

async function getBuildOrReleaseWorkItemsRefs(vstsWebApi: WebApi, settings: Settings): Promise<ResourceRef[]> {
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<ResourceRef[]> {
console.log('Using Query as WorkItem Source');
const result: ResourceRef[] = [];
Expand Down

0 comments on commit 8d258ef

Please sign in to comment.