This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 451
Adding Checkin and hooking it up to the viewlet #100
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
77b8b48
Added commit box hover provider
jpricket ab3016b
Added Checkin command and tests
jpricket f3a057a
Fixing checkin tests
jpricket f039523
Hooked up checkin to the viewlet
jpricket e1f01d6
Fixing merge error
jpricket b64c314
Small changes to improve checkin
jpricket File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
"use strict"; | ||
|
||
import { TeamServerContext} from "../../contexts/servercontext"; | ||
import { IArgumentProvider, IExecutionResult, ITfvcCommand } from "../interfaces"; | ||
import { ArgumentBuilder } from "./argumentbuilder"; | ||
import { CommandHelper } from "./commandhelper"; | ||
|
||
/** | ||
* This command checks in files into TFVC | ||
* <p/> | ||
* checkin [/all] [/author:<value>] [/comment:<value>|@valuefile] [/notes:"note"="value"[;"note2"="value2"[;...]]|@notefile] | ||
* [/override:<value>|@valuefile] [/recursive] [/validate] [/bypass] [/force] [/noautoresolve] [/associate:<workItemID>[,<workItemID>...]] | ||
* [/resolve:<workItemID>[,<workItemID>...]] [/saved] [<itemSpec>...] | ||
*/ | ||
export class Checkin implements ITfvcCommand<string> { | ||
private _serverContext: TeamServerContext; | ||
private _files: string[]; | ||
private _comment: string; | ||
private _workItemIds: number[]; | ||
|
||
public constructor(serverContext: TeamServerContext, files: string[], comment?: string, workItemIds?: number[]) { | ||
CommandHelper.RequireStringArrayArgument(files, "files"); | ||
this._serverContext = serverContext; | ||
this._files = files; | ||
this._comment = comment; | ||
this._workItemIds = workItemIds; | ||
} | ||
|
||
public GetArguments(): IArgumentProvider { | ||
const builder: ArgumentBuilder = new ArgumentBuilder("checkin", this._serverContext) | ||
.AddAll(this._files); | ||
if (this._comment) { | ||
builder.AddSwitchWithValue("comment", this.getComment(), false); | ||
} | ||
if (this._workItemIds && this._workItemIds.length > 0) { | ||
builder.AddSwitchWithValue("associate", this.getAssociatedWorkItems(), false); | ||
} | ||
return builder; | ||
} | ||
|
||
public GetOptions(): any { | ||
return {}; | ||
} | ||
|
||
private getComment(): string { | ||
// replace newlines with spaces | ||
return this._comment.replace(/\r\n/g, " ").replace(/\n/g, " "); | ||
} | ||
|
||
private getAssociatedWorkItems(): string { | ||
return this._workItemIds.join(","); | ||
} | ||
|
||
/** | ||
* Returns the files that were checked in | ||
* <p/> | ||
* Output example for success: | ||
* /Users/leantk/tfvc-tfs/tfsTest_01/addFold: | ||
* Checking in edit: testHere.txt | ||
* <p/> | ||
* /Users/leantk/tfvc-tfs/tfsTest_01: | ||
* Checking in edit: test3.txt | ||
* Checking in edit: TestAdd.txt | ||
* <p/> | ||
* Changeset #20 checked in. | ||
* <p/> | ||
* Output example for failure: | ||
* <p/> | ||
* /Users/leantk/tfvc-tfs/tfsTest_01: | ||
* Checking in edit: test3.txt | ||
* Checking in edit: TestAdd.txt | ||
* Unable to perform operation on $/tfsTest_01/TestAdd.txt. The item $/tfsTest_01/TestAdd.txt is locked in workspace new;Leah Antkiewicz. | ||
* No files checked in. | ||
* <p/> | ||
* No files checked in. | ||
*/ | ||
public async ParseOutput(executionResult: IExecutionResult): Promise<string> { | ||
if (executionResult.exitCode === 100) { | ||
CommandHelper.ProcessErrors(this.GetArguments().GetCommand(), executionResult, true); | ||
} else { | ||
return CommandHelper.GetChangesetNumber(executionResult.stdout); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
"use strict"; | ||
|
||
import { workspace, window, languages, Disposable, Uri, HoverProvider, Hover, TextEditor, Position, TextDocument, Range, TextEditorDecorationType, WorkspaceEdit } from "vscode"; | ||
import { Model } from "./model"; | ||
import { filterEvent } from "../util"; | ||
|
||
const scmInputUri = Uri.parse("scm:input"); | ||
|
||
function isSCMInput(uri: Uri) { | ||
return uri.toString() === scmInputUri.toString(); | ||
} | ||
|
||
interface Diagnostic { | ||
range: Range; | ||
message: string; | ||
} | ||
|
||
export class CommitHoverProvider implements HoverProvider { | ||
|
||
private decorationType: TextEditorDecorationType; | ||
private diagnostics: Diagnostic[] = []; | ||
private disposables: Disposable[] = []; | ||
private editor: TextEditor; | ||
private visibleTextEditorsDisposable: Disposable; | ||
|
||
constructor(private model: Model) { | ||
this.visibleTextEditorsDisposable = window.onDidChangeVisibleTextEditors(this.onVisibleTextEditors, this); | ||
this.onVisibleTextEditors(window.visibleTextEditors); | ||
|
||
this.decorationType = window.createTextEditorDecorationType({ | ||
isWholeLine: true, | ||
color: "rgb(228, 157, 43)", | ||
dark: { | ||
color: "rgb(220, 211, 71)" | ||
} | ||
}); | ||
} | ||
|
||
public get message(): string | undefined { | ||
if (!this.editor) { | ||
return; | ||
} | ||
|
||
return this.editor.document.getText(); | ||
} | ||
|
||
public set message(message: string | undefined) { | ||
if (!this.editor || message === undefined) { | ||
return; | ||
} | ||
|
||
const document = this.editor.document; | ||
const start = document.lineAt(0).range.start; | ||
const end = document.lineAt(document.lineCount - 1).range.end; | ||
const range = new Range(start, end); | ||
const edit = new WorkspaceEdit(); | ||
edit.replace(scmInputUri, range, message); | ||
workspace.applyEdit(edit); | ||
} | ||
|
||
private onVisibleTextEditors(editors: TextEditor[]): void { | ||
const [editor] = editors.filter(e => isSCMInput(e.document.uri)); | ||
|
||
if (!editor) { | ||
return; | ||
} | ||
|
||
this.visibleTextEditorsDisposable.dispose(); | ||
this.editor = editor; | ||
|
||
const onDidChange = filterEvent(workspace.onDidChangeTextDocument, e => e.document && isSCMInput(e.document.uri)); | ||
onDidChange(this.update, this, this.disposables); | ||
|
||
workspace.onDidChangeConfiguration(this.update, this, this.disposables); | ||
languages.registerHoverProvider({ scheme: "scm" }, this); | ||
} | ||
|
||
private update(): void { | ||
this.diagnostics = []; | ||
//TODO provide any diagnostic info based on the message here (see git commitcontroller) | ||
this.editor.setDecorations(this.decorationType, this.diagnostics.map(d => d.range)); | ||
} | ||
|
||
/* Implement HoverProvider */ | ||
provideHover(document: TextDocument, position: Position): Hover | undefined { | ||
const [decoration] = this.diagnostics.filter(d => d.range.contains(position)); | ||
|
||
if (!decoration) { | ||
return; | ||
} | ||
|
||
return new Hover(decoration.message, decoration.range); | ||
} | ||
|
||
dispose(): void { | ||
this.disposables.forEach(d => d.dispose()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,8 @@ import { TfvcSCMProvider } from "./tfvcscmprovider"; | |
import { TfvcErrorCodes } from "./tfvcerror"; | ||
import { Repository } from "./repository"; | ||
import { UIHelper } from "./uihelper"; | ||
import { IItemInfo, IPendingChange } from "./interfaces"; | ||
import { ICheckinInfo, IItemInfo, IPendingChange } from "./interfaces"; | ||
import { TfvcSCMProvider } from "./tfvcscmprovider"; | ||
import { TfvcOutput } from "./tfvcoutput"; | ||
|
||
export class TfvcExtension { | ||
|
@@ -31,7 +32,29 @@ export class TfvcExtension { | |
} | ||
|
||
public async TfvcCheckin(): Promise<void> { | ||
// | ||
if (!this._manager.EnsureInitialized(RepositoryType.TFVC)) { | ||
this._manager.DisplayErrorMessage(); | ||
return; | ||
} | ||
|
||
try { | ||
this._manager.Telemetry.SendEvent(TfvcTelemetryEvents.Checkin); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this down? |
||
|
||
// get the checkin info from the SCM viewlet | ||
const checkinInfo: ICheckinInfo = TfvcSCMProvider.GetCheckinInfo(); | ||
if (!checkinInfo) { | ||
// TODO localize | ||
window.showInformationMessage("There are no changes to checkin. Changes must be added to the 'Included' section to be checked in."); | ||
return; | ||
} | ||
|
||
const changeset: string = | ||
await this._repo.Checkin(checkinInfo.files, checkinInfo.comment, checkinInfo.workItemIds); | ||
//TODO should this be localized? | ||
TfvcOutput.AppendLine("Changeset " + changeset + " checked in."); | ||
} catch (err) { | ||
this._manager.DisplayErrorMessage(err.message); | ||
} | ||
} | ||
|
||
public async TfvcExclude(): Promise<void> { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo ==> Checkin