From 07a58cbd5bc8e0e405d61416994a622e8aeb8678 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 29 Aug 2023 21:27:28 +0200 Subject: [PATCH] GHPRI doesn't render suggestions in comments containing one-line deletions (#5212) Fixes #5211 --- src/github/prComment.ts | 12 ++++++------ src/view/reviewCommentController.ts | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/github/prComment.ts b/src/github/prComment.ts index 73b58961c2..57ecf9d8c1 100644 --- a/src/github/prComment.ts +++ b/src/github/prComment.ts @@ -186,7 +186,7 @@ export class TemporaryComment extends CommentBase { } } -const SUGGESTION_EXPRESSION = /```suggestion(\r\n|\n)([\s\S]*?)(\r\n|\n)```/; +const SUGGESTION_EXPRESSION = /```suggestion(\r\n|\n)(([\s\S]*?)(\r\n|\n))?```/; export class GHPRComment extends CommentBase { public commentId: string; @@ -229,7 +229,7 @@ export class GHPRComment extends CommentBase { contextValues.push('canDelete'); } - if (this.suggestion) { + if (this.suggestion !== undefined) { contextValues.push('hasSuggestion'); } @@ -258,7 +258,7 @@ export class GHPRComment extends CommentBase { contextValues.push('canDelete'); } - if (this.suggestion) { + if (this.suggestion !== undefined) { contextValues.push('hasSuggestion'); } @@ -287,8 +287,8 @@ export class GHPRComment extends CommentBase { get suggestion(): string | undefined { const suggestionBody = this.rawComment.body.match(SUGGESTION_EXPRESSION); - if (suggestionBody?.length === 4) { - return `${suggestionBody[2]}\n`; + if (suggestionBody?.length === 5) { + return suggestionBody[3] ? `${suggestionBody[3]}\n` : ''; } } @@ -301,7 +301,7 @@ export class GHPRComment extends CommentBase { return `*** Suggested change: \`\`\` -${args[1]} +${args[2] ?? ''} \`\`\` ***`; }); diff --git a/src/view/reviewCommentController.ts b/src/view/reviewCommentController.ts index 2898ea1cf2..fa91c73d86 100644 --- a/src/view/reviewCommentController.ts +++ b/src/view/reviewCommentController.ts @@ -897,7 +897,7 @@ export class ReviewCommentController async applySuggestion(comment: GHPRComment) { const range = comment.parent.range; const suggestion = comment.suggestion; - if (!suggestion || !range) { + if ((suggestion === undefined) || !range) { throw new Error('Comment doesn\'t contain a suggestion'); }