Skip to content

Commit

Permalink
fixed update api by using partial
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideCanton committed Nov 25, 2024
1 parent 4c48381 commit 7337428
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
7 changes: 5 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<gi.GitPullRequestCommentThread>;
}
Expand Down Expand Up @@ -177,13 +179,14 @@ class AzureRealClient implements AzureClient {

async updateThread(
pullRequestId: number,
threadId: number,
thread: gi.GitPullRequestCommentThread,
): Promise<gi.GitPullRequestCommentThread> {
return await this.gitClient.updateThread(
thread,
this.configuration.repositoryName,
pullRequestId,
thread.id!,
threadId,
this.configuration.projectName,
);
}
Expand Down
15 changes: 9 additions & 6 deletions src/comment-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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 =>
Expand Down
16 changes: 10 additions & 6 deletions src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ export class ExtensionController {
thread: vsc.CommentThread,
status: gi.CommentThreadStatus,
): Promise<void> {
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<void> {
Expand Down
6 changes: 5 additions & 1 deletion src/mocks/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ class MockClient implements AzureClient {

async updateThread(
pullRequestId: number,
threadId: number,
thread: gi.GitPullRequestCommentThread,
): Promise<gi.GitPullRequestCommentThread> {
return thread;
const t = THREADS.find(t => t.id === threadId)!;
const copy = JSON.parse(JSON.stringify(t));
copy.status = thread.status;
return t;
}
}

Expand Down

0 comments on commit 7337428

Please sign in to comment.