Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,16 @@
"category": "GitHub Pull Requests",
"enablement": "!commentIsEmpty"
},
{
"command": "pr.resolveReviewThread",
"title": "Resolve Conversation",
"category": "GitHub Pull Requests"
},
{
"command": "pr.unresolveReviewThread",
"title": "Unresolve Conversation",
"category": "GitHub Pull Requests"
},
{
"command": "pr.signinAndRefreshList",
"title": "Sign in and Refresh",
Expand Down Expand Up @@ -1310,32 +1320,32 @@
"comments/commentThread/context": [
{
"command": "pr.createComment",
"group": "inline",
"group": "inline@1",
"when": "commentController =~ /browse/ && prInDraft"
},
{
"command": "pr.createComment",
"group": "inline",
"group": "inline@1",
"when": "commentController =~ /review/ && reviewInDraftMode"
},
{
"command": "pr.createSingleComment",
"group": "inline",
"group": "inline@1",
"when": "commentController =~ /browse/ && !prInDraft"
},
{
"command": "pr.createSingleComment",
"group": "inline",
"group": "inline@1",
"when": "commentController =~ /review/ && !reviewInDraftMode"
},
{
"command": "pr.startReview",
"group": "inline",
"group": "inline@2",
"when": "commentController =~ /browse/ && !prInDraft"
},
{
"command": "pr.startReview",
"group": "inline",
"group": "inline@2",
"when": "commentController =~ /review/ && !reviewInDraftMode"
},
{
Expand All @@ -1357,6 +1367,16 @@
"command": "pr.finishReview",
"group": "inline",
"when": "commentController =~ /review/ && reviewInDraftMode"
},
{
"command": "pr.resolveReviewThread",
"group": "inline@3",
"when": "commentController =~ /browse|review/ && commentThread == canResolve"
},
{
"command": "pr.unresolveReviewThread",
"group": "inline@3",
"when": "commentController =~ /browse|review/ && commentThread == canUnresolve"
}
],
"comments/comment/title": [
Expand Down
28 changes: 28 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,34 @@ export function registerCommands(
}),
);

context.subscriptions.push(
vscode.commands.registerCommand('pr.resolveReviewThread', async (reply: CommentReply) => {
/* __GDPR__
"pr.resolveReviewThread" : {}
*/
telemetry.sendTelemetryEvent('pr.resolveReviewThread');
const handler = resolveCommentHandler(reply.thread);

if (handler) {
await handler.resolveReviewThread(reply.thread, reply.text);
}
})
);

context.subscriptions.push(
vscode.commands.registerCommand('pr.unresolveReviewThread', async (reply: CommentReply) => {
/* __GDPR__
"pr.unresolveReviewThread" : {}
*/
telemetry.sendTelemetryEvent('pr.unresolveReviewThread');
const handler = resolveCommentHandler(reply.thread);

if (handler) {
await handler.unresolveReviewThread(reply.thread, reply.text);
}
})
);

context.subscriptions.push(
vscode.commands.registerCommand('pr.createComment', async (reply: CommentReply) => {
/* __GDPR__
Expand Down
3 changes: 3 additions & 0 deletions src/commentHandlerResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export interface CommentHandler {
startReview(thread: GHPRCommentThread, input: string): Promise<void>;
finishReview(thread: GHPRCommentThread, input: string): Promise<void>;
deleteReview(): Promise<void>;

resolveReviewThread(thread: GHPRCommentThread, input?: string): Promise<void>;
unresolveReviewThread(thread: GHPRCommentThread, input?: string): Promise<void>;
}

export interface CommentReply {
Expand Down
1 change: 1 addition & 0 deletions src/common/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface IReviewThread {
id: string;
isResolved: boolean;
viewerCanResolve: boolean;
viewerCanUnresolve: boolean;
path: string;
diffSide: DiffSide;
line: number;
Expand Down
29 changes: 14 additions & 15 deletions src/github/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export interface ReviewThread {
id: string;
isResolved: boolean;
viewerCanResolve: boolean;
viewerCanUnresolve: boolean;
path: string;
diffSide: DiffSide;
line: number;
Expand Down Expand Up @@ -210,21 +211,7 @@ export interface PullRequestCommentsResponse {
repository: {
pullRequest: {
reviewThreads: {
nodes: [
{
id: string;
isResolved: boolean;
viewerCanResolve: boolean;
path: string;
diffSide: DiffSide;
line: number;
originalLine: number;
isOutdated: boolean;
comments: {
nodes: ReviewComment[];
};
},
];
nodes: ReviewThread[];
};
};
};
Expand Down Expand Up @@ -615,3 +602,15 @@ export interface GetChecksResponse {
};
};
}

export interface ResolveReviewThreadResponse {
resolveReviewThread: {
thread: ReviewThread;
}
}

export interface UnresolveReviewThreadResponse {
unresolveReviewThread: {
thread: ReviewThread;
}
}
67 changes: 44 additions & 23 deletions src/github/pullRequestModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@ import {
PullRequestCommentsResponse,
PullRequestResponse,
ReactionGroup,
ResolveReviewThreadResponse,
StartReviewResponse,
SubmitReviewResponse,
TimelineEventsResponse,
UnresolveReviewThreadResponse,
UpdatePullRequestResponse,
} from './graphql';
import {
Expand All @@ -57,6 +59,7 @@ import {
parseGraphQLComment,
parseGraphQLReaction,
parseGraphQLReviewEvent,
parseGraphQLReviewThread,
parseGraphQLTimelineEvents,
parseMergeability,
} from './utils';
Expand Down Expand Up @@ -426,7 +429,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
}
const pendingReviewId = await this.getPendingReviewId();

const { mutate, schema, remote } = await this.githubRepository.ensure();
const { mutate, schema } = await this.githubRepository.ensure();
const { data } = await mutate<AddReviewThreadResponse>({
mutation: schema.AddReviewThread,
variables: {
Expand All @@ -447,17 +450,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
}

const thread = data.addPullRequestReviewThread.thread;
const newThread = {
id: thread.id,
isResolved: thread.isResolved,
viewerCanResolve: thread.viewerCanResolve,
path: thread.path,
line: thread.line,
originalLine: thread.originalLine,
diffSide: thread.diffSide,
isOutdated: thread.isOutdated,
comments: thread.comments.nodes.map(comment => parseGraphQLComment(comment, thread.isResolved), remote),
};
const newThread = parseGraphQLReviewThread(thread);
this._reviewThreadsCache.push(newThread);
this._onDidChangeReviewThreads.fire({ added: [newThread], changed: [], removed: [] });
return newThread;
Expand Down Expand Up @@ -694,17 +687,7 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe
});

const reviewThreads = data.repository.pullRequest.reviewThreads.nodes.map(node => {
return {
id: node.id,
isResolved: node.isResolved,
viewerCanResolve: node.viewerCanResolve,
path: node.path,
line: node.line,
originalLine: node.originalLine,
diffSide: node.diffSide,
isOutdated: node.isOutdated,
comments: node.comments.nodes.map(comment => parseGraphQLComment(comment, node.isResolved), remote),
};
return parseGraphQLReviewThread(node);
});

this.diffThreads(reviewThreads);
Expand Down Expand Up @@ -1202,4 +1185,42 @@ export class PullRequestModel extends IssueModel<PullRequest> implements IPullRe

return data;
}

async resolveReviewThread(threadId: string): Promise<void> {
const { mutate, schema } = await this.githubRepository.ensure();
const { data } = await mutate<ResolveReviewThreadResponse>({
mutation: schema.ResolveReviewThread,
variables: {
input: {
threadId,
},
},
});

const index = this._reviewThreadsCache.findIndex(thread => thread.id === threadId);
if (index > -1) {
const thread = parseGraphQLReviewThread(data.resolveReviewThread.thread);
this._reviewThreadsCache.splice(index, 1, thread);
this._onDidChangeReviewThreads.fire({ added: [], changed: [thread], removed: [] });
}
}

async unresolveReviewThread(threadId: string): Promise<void> {
const { mutate, schema } = await this.githubRepository.ensure();
const { data } = await mutate<UnresolveReviewThreadResponse>({
mutation: schema.UnresolveReviewThread,
variables: {
input: {
threadId,
},
},
});

const index = this._reviewThreadsCache.findIndex(thread => thread.id === threadId);
if (index > -1) {
const thread = parseGraphQLReviewThread(data.unresolveReviewThread.thread);
this._reviewThreadsCache.splice(index, 1, thread);
this._onDidChangeReviewThreads.fire({ added: [], changed: [thread], removed: [] });
}
}
}
18 changes: 18 additions & 0 deletions src/github/queries.gql
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fragment ReviewThread on PullRequestReviewThread {
id
isResolved
viewerCanResolve
viewerCanUnresolve
path
diffSide
line
Expand Down Expand Up @@ -246,6 +247,7 @@ query PullRequestComments($owner: String!, $name: String!, $number: Int!, $first
id
isResolved
viewerCanResolve
viewerCanUnresolve
path
diffSide
line
Expand Down Expand Up @@ -849,3 +851,19 @@ query GetChecks($owner: String!, $name: String!, $number: Int!) {
}
}
}

mutation ResolveReviewThread($input: ResolveReviewThreadInput!) {
resolveReviewThread(input: $input) {
thread {
...ReviewThread
}
}
}

mutation UnresolveReviewThread($input: UnresolveReviewThreadInput!) {
unresolveReviewThread(input: $input) {
thread {
...ReviewThread
}
}
}
44 changes: 44 additions & 0 deletions src/github/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export function createVSCodeCommentThreadForReviewThread(
vscodeThread.comments = thread.comments.map(comment => new GHPRComment(comment, vscodeThread as GHPRCommentThread));
(vscodeThread as GHPRCommentThread).isResolved = thread.isResolved;

if (thread.viewerCanResolve && !thread.isResolved) {
vscodeThread.contextValue = 'canResolve';
} else if (thread.viewerCanUnresolve && thread.isResolved) {
vscodeThread.contextValue = 'canUnresolve';
}

updateCommentThreadLabel(vscodeThread as GHPRCommentThread);
const isOnLocalFile = uri.scheme !== 'pr' && uri.scheme !== 'review';
vscodeThread.collapsibleState =
Expand All @@ -56,7 +62,30 @@ export function createVSCodeCommentThreadForReviewThread(
return vscodeThread as GHPRCommentThread;
}

export function updateThread(vscodeThread: GHPRCommentThread, reviewThread: IReviewThread) {
if (reviewThread.viewerCanResolve && !reviewThread.isResolved) {
vscodeThread.contextValue = 'canResolve';
} else if (reviewThread.viewerCanUnresolve && reviewThread.isResolved) {
vscodeThread.contextValue = 'canUnresolve';
}

if (vscodeThread.isResolved !== reviewThread.isResolved) {
vscodeThread.isResolved = reviewThread.isResolved;
vscodeThread.collapsibleState = reviewThread.isResolved
? vscode.CommentThreadCollapsibleState.Collapsed
: vscode.CommentThreadCollapsibleState.Expanded;
}

vscodeThread.comments = reviewThread.comments.map(c => new GHPRComment(c, vscodeThread));
updateCommentThreadLabel(vscodeThread);
}

export function updateCommentThreadLabel(thread: GHPRCommentThread) {
if (thread.isResolved) {
thread.label = 'This thread has been marked as resolved';
return;
}

if (thread.comments.length) {
const participantsList = uniqBy(thread.comments as vscode.Comment[], comment => comment.author.name)
.map(comment => `@${comment.author.name}`)
Expand Down Expand Up @@ -305,6 +334,21 @@ export function convertGraphQLEventType(text: string) {
}
}

export function parseGraphQLReviewThread(thread: GraphQL.ReviewThread): IReviewThread {
return {
id: thread.id,
isResolved: thread.isResolved,
viewerCanResolve: thread.viewerCanResolve,
viewerCanUnresolve: thread.viewerCanUnresolve,
path: thread.path,
line: thread.line,
originalLine: thread.originalLine,
diffSide: thread.diffSide,
isOutdated: thread.isOutdated,
comments: thread.comments.nodes.map(comment => parseGraphQLComment(comment, thread.isResolved)),
};
}

export function parseGraphQLComment(comment: GraphQL.ReviewComment, isResolved: boolean): IComment {
const c: IComment = {
id: comment.databaseId,
Expand Down
1 change: 1 addition & 0 deletions src/test/view/reviewCommentController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ describe('ReviewCommentController', function () {
id: '1',
isResolved: false,
viewerCanResolve: false,
viewerCanUnresolve: false,
path: fileName,
diffSide: DiffSide.RIGHT,
line: 372,
Expand Down
Loading