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

Commit

Permalink
Merge pull request #107 from Microsoft/users/jpricket/0213
Browse files Browse the repository at this point in the history
Some refactoring and parsing of WIT ids from commit message
  • Loading branch information
jpricket authored Feb 15, 2017
2 parents 8d7aced + 8d06fa5 commit 70d055a
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 116 deletions.
24 changes: 12 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,30 +45,30 @@ export async function activate(context: ExtensionContext) {
context.subscriptions.push(commands.registerCommand(CommandNames.Reinitialize, () => _extensionManager.Reinitialize()));

// TFVC Commands
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Status, () => _extensionManager.Tfvc.TfvcStatus()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Status, () => _extensionManager.Tfvc.Status()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Undo, (...args) => {
_extensionManager.Tfvc.TfvcUndo(args ? args[0] : undefined);
_extensionManager.Tfvc.Undo(args ? args[0] : undefined);
}));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Exclude, (...args) => {
_extensionManager.Tfvc.TfvcExclude(args ? args[0] : undefined);
_extensionManager.Tfvc.Exclude(args ? args[0] : undefined);
}));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Include, (...args) => {
_extensionManager.Tfvc.TfvcInclude(args ? args[0] : undefined);
_extensionManager.Tfvc.Include(args ? args[0] : undefined);
}));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.OpenDiff, (...args) => {
_extensionManager.Tfvc.TfvcOpenDiff(args ? args[0] : undefined);
_extensionManager.Tfvc.OpenDiff(args ? args[0] : undefined);
}));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.OpenFile, (...args) => {
_extensionManager.Tfvc.TfvcOpenFile(args ? args[0] : undefined);
_extensionManager.Tfvc.OpenFile(args ? args[0] : undefined);
}));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Refresh, () => _extensionManager.Tfvc.TfvcRefresh()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.ShowOutput, () => _extensionManager.Tfvc.TfvcShowOutput()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Refresh, () => _extensionManager.Tfvc.Refresh()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.ShowOutput, () => _extensionManager.Tfvc.ShowOutput()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.ResolveKeepYours, (...args) => {
_extensionManager.Tfvc.TfvcResolve(args ? args[0] : undefined, AutoResolveType.KeepYours);
_extensionManager.Tfvc.Resolve(args ? args[0] : undefined, AutoResolveType.KeepYours);
}));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.ResolveTakeTheirs, (...args) => {
_extensionManager.Tfvc.TfvcResolve(args ? args[0] : undefined, AutoResolveType.TakeTheirs);
_extensionManager.Tfvc.Resolve(args ? args[0] : undefined, AutoResolveType.TakeTheirs);
}));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Checkin, () => _extensionManager.Tfvc.TfvcCheckin()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Sync, () => _extensionManager.Tfvc.TfvcSync()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Checkin, () => _extensionManager.Tfvc.Checkin()));
context.subscriptions.push(commands.registerCommand(TfvcCommandNames.Sync, () => _extensionManager.Tfvc.Sync()));
}
2 changes: 1 addition & 1 deletion src/team-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class TeamExtension {
if (this._manager.RepoContext.Type === RepositoryType.GIT && this._gitClient) {
this._gitClient.OpenFileHistory(this._manager.RepoContext);
} else if (this._manager.RepoContext.Type === RepositoryType.TFVC) {
this._manager.Tfvc.TfvcViewHistory();
this._manager.Tfvc.ViewHistory();
} else {
this._manager.DisplayErrorMessage(Strings.NoRepoInformation);
}
Expand Down
12 changes: 6 additions & 6 deletions src/tfvc/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ export class Repository {
return this._repositoryRootFolder;
}

public async Checkin(files: string[], comment: string, workItemIds: number[]): Promise<string> {
Logger.LogDebug(`TFVC Repository.Checkin`);
return this.RunCommand<string>(
new Checkin(this._serverContext, files, comment, workItemIds));
}

public async Add(itemPaths: string[]): Promise<string[]> {
Logger.LogDebug(`TFVC Repository.Add`);
return this.RunCommand<string[]>(
new Add(this._serverContext, itemPaths));
}

public async Checkin(files: string[], comment: string, workItemIds: number[]): Promise<string> {
Logger.LogDebug(`TFVC Repository.Checkin`);
return this.RunCommand<string>(
new Checkin(this._serverContext, files, comment, workItemIds));
}

public async FindConflicts(itemPath?: string): Promise<IConflict[]> {
Logger.LogDebug(`TFVC Repository.FindConflicts`);
return this.RunCommand<IConflict[]>(
Expand Down
137 changes: 41 additions & 96 deletions src/tfvc/tfvc-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,8 @@ export class TfvcExtension {
this._manager = manager;
}

public async TfvcCheckin(): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
public async Checkin(): Promise<void> {
this.displayErrors(async () => {
// get the checkin info from the SCM viewlet
const checkinInfo: ICheckinInfo = TfvcSCMProvider.GetCheckinInfo();
if (!checkinInfo) {
Expand All @@ -51,91 +46,62 @@ export class TfvcExtension {
await this._repo.Checkin(checkinInfo.files, checkinInfo.comment, checkinInfo.workItemIds);
TfvcOutput.AppendLine("Changeset " + changeset + " checked in.");
TfvcSCMProvider.ClearCheckinMessage();
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
}
});
}

public async TfvcExclude(uri?: Uri): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

public async Exclude(uri?: Uri): Promise<void> {
this.displayErrors(async () => {
if (uri) {
//Keep an in-memory list of items that were explicitly excluded. The list is not persisted at this time.
await TfvcSCMProvider.Exclude(TfvcSCMProvider.GetPathFromUri(uri));
}
});
}

public async TfvcInclude(uri?: Uri): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}
public async Include(uri?: Uri): Promise<void> {
this.displayErrors(async () => {
if (uri) {
let resource: Resource = TfvcSCMProvider.ResolveTfvcResource(uri);
let path: string = TfvcSCMProvider.GetPathFromUri(uri);

if (uri) {
let resource: Resource = TfvcSCMProvider.ResolveTfvcResource(uri);
let path: string = TfvcSCMProvider.GetPathFromUri(uri);
//At this point, an unversioned file could be a candidate file, so call Add. Once it is added, it should be a Pending change.
if (!resource.IsVersioned) {
await this._repo.Add([path]);
//Don't return after adding, we may still need to unexclude it (it may have been excluded previously)
}

//At this point, an unversioned file could be a candidate file, so call Add. Once it is added, it should be a Pending change.
if (!resource.IsVersioned) {
await this._repo.Add([path]);
//Don't return after adding, we may still need to unexclude it (it may have been excluded previously)
//Otherwise, ensure its not in the explicitly excluded list (if it's already there)
//Unexclude doesn't explicitly INclude. It defers to the status of the individual item.
await TfvcSCMProvider.Unexclude(path);
}

//Otherwise, ensure its not in the explicitly excluded list (if it's already there)
//Unexclude doesn't explicitly INclude. It defers to the status of the individual item.
await TfvcSCMProvider.Unexclude(path);
}
});
}

public async TfvcOpenDiff(uri?: Uri): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
public async OpenDiff(uri?: Uri): Promise<void> {
this.displayErrors(async () => {
if (uri) {
let resource: Resource = TfvcSCMProvider.ResolveTfvcResource(uri);
TfvcSCMProvider.OpenDiff(resource);
}
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
}
});
}

public async TfvcOpenFile(uri?: Uri): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
public async OpenFile(uri?: Uri): Promise<void> {
this.displayErrors(async () => {
if (uri) {
let path: string = TfvcSCMProvider.GetPathFromUri(uri);
await window.showTextDocument(await workspace.openTextDocument(path));
}
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
}
});
}

public async TfvcRefresh(): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
public async Refresh(): Promise<void> {
this.displayErrors(async () => {
TfvcSCMProvider.Refresh();
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
}
});
}

public async TfvcResolve(uri: Uri, autoResolveType: AutoResolveType): Promise<void> {
public async Resolve(uri: Uri, autoResolveType: AutoResolveType): Promise<void> {
this.displayErrors(async () => {
if (uri) {
let localPath: string = TfvcSCMProvider.GetPathFromUri(uri);
Expand All @@ -152,7 +118,7 @@ export class TfvcExtension {
});
}

public async TfvcShowOutput(): Promise<void> {
public async ShowOutput(): Promise<void> {
TfvcOutput.Show();
}

Expand All @@ -161,54 +127,35 @@ export class TfvcExtension {
* displays the results to the user. Selecting one of the files in the list will
* open the file in the editor.
*/
public async TfvcStatus(): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
public async Status(): Promise<void> {
this.displayErrors(async () => {
Telemetry.SendEvent(TfvcTelemetryEvents.Status);
const chosenItem: IPendingChange = await UIHelper.ChoosePendingChange(await this._repo.GetStatus());
if (chosenItem) {
window.showTextDocument(await workspace.openTextDocument(chosenItem.localItem));
}
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
}
});
}

/**
* This command runs a 'tf get' command on the VSCode workspace folder and
* displays the results to the user.
*/
public async TfvcSync(): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
public async Sync(): Promise<void> {
this.displayErrors(async () => {
Telemetry.SendEvent(TfvcTelemetryEvents.Sync);
const results: ISyncResults = await this._repo.Sync([this._repo.Path], true);
await UIHelper.ShowSyncResults(results, results.hasConflicts || results.hasErrors, true);
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
}
});
}

/**
* This command runs an undo command on the currently open file in the VSCode workspace folder and
* editor. If the undo command applies to the file, the pending changes will be undone. The
* file system watcher will update the UI soon thereafter. No results are displayed to the user.
*/
public async TfvcUndo(uri?: Uri): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
}

try {
public async Undo(uri?: Uri): Promise<void> {
this.displayErrors(async () => {
//When calling from UI, we have the uri of the resource from which the command was invoked
let pathToUndo: string = TfvcSCMProvider.GetPathFromUri(uri);
if (!pathToUndo) {
Expand All @@ -225,16 +172,14 @@ export class TfvcExtension {
await this._repo.Undo([pathToUndo]);
}
}
} catch (err) {
this._manager.DisplayErrorMessage(err.message);
}
});
}

/**
* This command runs the info command on the passed in itemPath and
* opens a web browser to the appropriate history page.
*/
public async TfvcViewHistory(): Promise<void> {
public async ViewHistory(): Promise<void> {
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) {
this._manager.DisplayErrorMessage();
return;
Expand Down
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 70d055a

Please sign in to comment.