From 733742859c6aea63f82c11086c02a3e20477c90f Mon Sep 17 00:00:00 2001 From: Davide Canton Date: Mon, 25 Nov 2024 01:26:40 +0100 Subject: [PATCH] fixed update api by using partial --- src/client.ts | 7 +++++-- src/comment-handler.ts | 15 +++++++++------ src/controller.ts | 16 ++++++++++------ src/mocks/client.ts | 6 +++++- 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/client.ts b/src/client.ts index 90c22c2..e4121e8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -65,11 +65,13 @@ export interface AzureClient { /** * Updates a comment thread. * @param pullRequestId The ID of the pull request. - * @param thread The thread to update. + * @param threadId The thread id to update. + * @param thread The partial body of the thread with the fields to update. * @returns The updated thread. */ updateThread( pullRequestId: number, + threadId: number, thread: gi.GitPullRequestCommentThread, ): Promise; } @@ -177,13 +179,14 @@ class AzureRealClient implements AzureClient { async updateThread( pullRequestId: number, + threadId: number, thread: gi.GitPullRequestCommentThread, ): Promise { return await this.gitClient.updateThread( thread, this.configuration.repositoryName, pullRequestId, - thread.id!, + threadId, this.configuration.projectName, ); } diff --git a/src/comment-handler.ts b/src/comment-handler.ts index 68684ed..354e9e0 100644 --- a/src/comment-handler.ts +++ b/src/comment-handler.ts @@ -248,10 +248,12 @@ class CommentHandlerImpl implements CommentHandler { } let content = comment.content!; - content = content.replace( - /```suggestion/g, - '**Suggestion**:\n```suggestion', - ); + if (content) { + content = content.replace( + /```suggestion/g, + '**Suggestion**:\n```suggestion', + ); + } comments.push( CommentImpl.createComment( @@ -393,10 +395,11 @@ class CommentHandlerImpl implements CommentHandler { const lastComment = last(thread.comments) as CommentImpl; const azureThread = lastComment.azureThread; if (azureThread.status !== status) { - azureThread.status = status; + const threadUpdate: gi.GitPullRequestCommentThread = { status }; const updated = await client.updateThread( pullRequestId, - azureThread, + azureThread.id!, + threadUpdate, ); thread.comments = [ ...thread.comments.map(c => diff --git a/src/controller.ts b/src/controller.ts index 73781b7..3007809 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -122,12 +122,16 @@ export class ExtensionController { thread: vsc.CommentThread, status: gi.CommentThreadStatus, ): Promise { - await this.commentHandler.updateStatus( - thread, - status, - this.pullRequest!.pullRequestId!, - this.client, - ); + try { + await this.commentHandler.updateStatus( + thread, + status, + this.pullRequest!.pullRequestId!, + this.client, + ); + } catch (error) { + debugger; + } } private async replyToThread(reply: vsc.CommentReply): Promise { diff --git a/src/mocks/client.ts b/src/mocks/client.ts index a5480b2..88a6206 100644 --- a/src/mocks/client.ts +++ b/src/mocks/client.ts @@ -45,9 +45,13 @@ class MockClient implements AzureClient { async updateThread( pullRequestId: number, + threadId: number, thread: gi.GitPullRequestCommentThread, ): Promise { - return thread; + const t = THREADS.find(t => t.id === threadId)!; + const copy = JSON.parse(JSON.stringify(t)); + copy.status = thread.status; + return t; } }