Skip to content

Commit

Permalink
Add support for linked work items from git using AB#123 format
Browse files Browse the repository at this point in the history
  • Loading branch information
rfennell committed Jul 2, 2021
1 parent 8c965cc commit 9b6b499
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
35 changes: 33 additions & 2 deletions Extensions/XplatGenerateReleaseNotes/V3/ReleaseNotesFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,6 @@ export async function generateReleaseNotes(
// remove duplicates
agentApi.logInfo("Removing duplicate Commits from master list");
globalCommits = removeDuplicates(globalCommits);
agentApi.logInfo("Removing duplicate WorkItems from master list");
globalWorkItems = removeDuplicates(globalWorkItems);

let expandedGlobalCommits = await expandTruncatedCommitMessages(organisationWebApi, globalCommits, gitHubPat, bitbucketUser, bitbucketSecret);

Expand All @@ -1514,6 +1512,12 @@ export async function generateReleaseNotes(
return;
}

agentApi.logInfo("Find any WorkItems linked from GitHub using the AB#123 format");
globalWorkItems = globalWorkItems.concat(await addGitHubLinkedWI(workItemTrackingApi, globalCommits));

agentApi.logInfo("Removing duplicate WorkItems from master list");
globalWorkItems = removeDuplicates(globalWorkItems);

// get an array of workitem ids
fullWorkItems = await getFullWorkItemDetails(workItemTrackingApi, globalWorkItems);

Expand Down Expand Up @@ -1743,3 +1747,30 @@ function removeDuplicates(array: any[]): any[] {
)));
return array;
}

async function addGitHubLinkedWI(workItemTrackingApi: IWorkItemTrackingApi, globalCommits: Change[]): Promise<ResourceRef[]> {
return new Promise<ResourceRef[]>(async (resolve, reject) => {
var workItems = [];
try {
for (var commitIndex = 0; commitIndex < globalCommits.length; commitIndex++) {
var commit = globalCommits[commitIndex];
if (commit.type && commit.type === "GitHub") {
// this is a commit from github, so check for AB#123 links
if (commit.message) {
var linkedWIs = commit.message.match(/(ab#)[0-9]+/ig);
agentApi.logInfo(`Found ${linkedWIs.length} workitems linked using the AB#123 format`);
if (linkedWIs) {
for (let wiIndex = 0; wiIndex < linkedWIs.length; wiIndex++) {
const wi = Number(linkedWIs[wiIndex].substr(3));
workItems.push(await workItemTrackingApi.getWorkItem(wi, null, null, WorkItemExpand.All, null));
}
}
}
}
}
resolve (workItems);
} catch (err) {
reject (err);
}
});
}
1 change: 1 addition & 0 deletions Extensions/XplatGenerateReleaseNotes/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Generates release notes for a Classic Build or Release, or a YML based build. The generated file can be any text based format of your choice
* Can be used on any type of Azure DevOps Agents (Windows, Mac or Linux)
* Uses same logic as Azure DevOps Release UI to work out the work items and commits/changesets associated with the release
* 3.54.x Added support to find WI linked from GitHub using the `AB#123` syntax and adding them to the `workitems` array
* 3.52.x Added enrichement of pipeline `consumedArtifacts` to include commits and workitem associated where possible
* 3.50.x Added `consumedArtifacts` to the available options in the template
* 3.46.x Added `manualtest` and `manualTestConfigurations` to the available options in the template
Expand Down

0 comments on commit 9b6b499

Please sign in to comment.