Skip to content

Commit 56448a5

Browse files
authored
Merge pull request #1171 from microsoft/rebornix/no-dup-authentication
Avoid uncessary authentication
2 parents a06e378 + 15f9356 commit 56448a5

File tree

2 files changed

+26
-30
lines changed

2 files changed

+26
-30
lines changed

src/view/reviewDocumentCommentProvider.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,19 @@ export class ReviewDocumentCommentProvider implements vscode.Disposable, Comment
328328
// #region New Comment Thread
329329

330330
async createEmptyCommentThread(document: vscode.TextDocument, range: vscode.Range): Promise<void> {
331-
if (await this._prManager.authenticate()) {
332-
const inDraftMode = await this._prManager.inDraftMode(this._prManager.activePullRequest!);
333-
// threadIds must be unique, otherwise they will collide when vscode saves pending comment text. Assumes
334-
// that only one empty thread can be created per line.
335-
const threadId = document.uri.toString() + range.start.line;
336-
const thread = this._commentController!.createCommentThread(threadId, document.uri, range, []);
337-
thread.collapsibleState = vscode.CommentThreadCollapsibleState.Expanded;
331+
const inDraftMode = await this._prManager.inDraftMode(this._prManager.activePullRequest!);
332+
// threadIds must be unique, otherwise they will collide when vscode saves pending comment text. Assumes
333+
// that only one empty thread can be created per line.
334+
const threadId = document.uri.toString() + range.start.line;
335+
const thread = this._commentController!.createCommentThread(threadId, document.uri, range, []);
336+
thread.collapsibleState = vscode.CommentThreadCollapsibleState.Expanded;
338337

339-
const commands = getAcceptInputCommands(thread, inDraftMode, this, this._prManager.activePullRequest!.githubRepository.supportsGraphQl);
338+
const commands = getAcceptInputCommands(thread, inDraftMode, this, this._prManager.activePullRequest!.githubRepository.supportsGraphQl);
340339

341-
thread.acceptInputCommand = commands.acceptInputCommand;
342-
thread.additionalCommands = commands.additionalCommands;
343-
thread.deleteCommand = getDeleteThreadCommand(thread);
344-
updateCommentThreadLabel(thread);
345-
}
340+
thread.acceptInputCommand = commands.acceptInputCommand;
341+
thread.additionalCommands = commands.additionalCommands;
342+
thread.deleteCommand = getDeleteThreadCommand(thread);
343+
updateCommentThreadLabel(thread);
346344
}
347345

348346
private addToCommentThreadCache(thread: vscode.CommentThread): void {
@@ -823,7 +821,7 @@ export class ReviewDocumentCommentProvider implements vscode.Disposable, Comment
823821

824822
// #region Comment
825823
async createOrReplyComment(thread: vscode.CommentThread): Promise<void> {
826-
if (await this._prManager.authenticate() && this.commentController!.inputBox) {
824+
if (this.commentController!.inputBox) {
827825
if (thread.comments.length) {
828826
let comment = thread.comments[0] as (vscode.Comment & { _rawComment: Comment });
829827
const rawComment = await this._prManager.createCommentReply(this._prManager.activePullRequest!, this.commentController!.inputBox!.value, comment._rawComment);
@@ -843,7 +841,7 @@ export class ReviewDocumentCommentProvider implements vscode.Disposable, Comment
843841

844842
async editComment(thread: vscode.CommentThread, comment: vscode.Comment): Promise<void> {
845843
try {
846-
if (!await this._prManager.authenticate() || !this._commentController!.inputBox) {
844+
if (!this._commentController!.inputBox) {
847845
return;
848846
}
849847

src/view/treeNodes/pullRequestNode.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -453,19 +453,17 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
453453

454454
// #region New Comment Thread
455455
async createEmptyCommentThread(document: vscode.TextDocument, range: vscode.Range): Promise<void> {
456-
if (await this._prManager.authenticate()) {
457-
const inDraftMode = await this._prManager.inDraftMode(this.pullRequestModel);
458-
// threadIds must be unique, otherwise they will collide when vscode saves pending comment text. Assumes
459-
// that only one empty thread can be created per line.
460-
const threadId = document.uri.toString() + range.start.line;
461-
const thread = this._commentController!.createCommentThread(threadId, document.uri, range, []);
462-
updateCommentThreadLabel(thread);
463-
thread.collapsibleState = vscode.CommentThreadCollapsibleState.Expanded;
464-
let commands = getAcceptInputCommands(thread, inDraftMode, this, this.pullRequestModel.githubRepository.supportsGraphQl);
465-
thread.acceptInputCommand = commands.acceptInputCommand;
466-
thread.additionalCommands = commands.additionalCommands;
467-
thread.deleteCommand = getDeleteThreadCommand(thread);
468-
}
456+
const inDraftMode = await this._prManager.inDraftMode(this.pullRequestModel);
457+
// threadIds must be unique, otherwise they will collide when vscode saves pending comment text. Assumes
458+
// that only one empty thread can be created per line.
459+
const threadId = document.uri.toString() + range.start.line;
460+
const thread = this._commentController!.createCommentThread(threadId, document.uri, range, []);
461+
updateCommentThreadLabel(thread);
462+
thread.collapsibleState = vscode.CommentThreadCollapsibleState.Expanded;
463+
let commands = getAcceptInputCommands(thread, inDraftMode, this, this.pullRequestModel.githubRepository.supportsGraphQl);
464+
thread.acceptInputCommand = commands.acceptInputCommand;
465+
thread.additionalCommands = commands.additionalCommands;
466+
thread.deleteCommand = getDeleteThreadCommand(thread);
469467
}
470468

471469
private async updateCommentThreadRoot(thread: vscode.CommentThread, text: string): Promise<void> {
@@ -645,7 +643,7 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
645643

646644
// #region comment
647645
public async createOrReplyComment(thread: vscode.CommentThread) {
648-
if (await this._prManager.authenticate() && this.commentController!.inputBox !== undefined) {
646+
if (this.commentController!.inputBox !== undefined) {
649647
if (thread.comments.length) {
650648
let comment = thread.comments[0] as (vscode.Comment & { _rawComment: Comment });
651649
const rawComment = await this._prManager.createCommentReply(this.pullRequestModel, this.commentController!.inputBox!.value, comment._rawComment);
@@ -667,7 +665,7 @@ export class PRNode extends TreeNode implements CommentHandler, vscode.Commentin
667665
}
668666

669667
public async editComment(thread: vscode.CommentThread, comment: vscode.Comment): Promise<void> {
670-
if (await this._prManager.authenticate() && this._commentController!.inputBox) {
668+
if (this._commentController!.inputBox) {
671669
const fileChange = this.findMatchingFileNode(thread.resource);
672670
const existingComment = (comment as (vscode.Comment & { _rawComment: Comment }))._rawComment;
673671
if (!existingComment) {

0 commit comments

Comments
 (0)