Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Parsing work item ids out of message for associate
Browse files Browse the repository at this point in the history
  • Loading branch information
jpricket committed Feb 15, 2017
1 parent 41f660e commit 8d06fa5
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/tfvc/tfvcscmprovider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class TfvcSCMProvider implements SCMProvider {
try {
const files: string[] = [];
const commitMessage: string = scm.inputBox.value;
const workItemIds: number[] = [];
const workItemIds: number[] = TfvcSCMProvider.getWorkItemIdsFromMessage(commitMessage);

const resources: Resource[] = tfvcProvider._model.IncludedGroup.resources;
if (!resources || resources.length === 0) {
Expand All @@ -72,6 +72,26 @@ export class TfvcSCMProvider implements SCMProvider {
}
}

private static getWorkItemIdsFromMessage(message: string) {
let ids: number[] = [];
try {
// Find all the work item mentions in the string.
// This returns an array like: ["#1", "#12", "#33"]
const matches: string[] = message ? message.match(/#(\d+)/gm) : [];
if (matches) {
for (let i: number = 0; i < matches.length; i++) {
const id: number = parseInt(matches[i].slice(1));
if (!isNaN(id)) {
ids.push(id);
}
}
}
} catch (err) {
Logger.LogDebug("Failed to get all workitems from message: " + message);
}
return ids;
}

public static async Exclude(path: string): Promise<void> {
const tfvcProvider: TfvcSCMProvider = TfvcSCMProvider.GetProviderInstance();

Expand Down

0 comments on commit 8d06fa5

Please sign in to comment.