Skip to content

Commit

Permalink
GHPRI doesn't render suggestions in comments containing one-line dele…
Browse files Browse the repository at this point in the history
…tions (#5212)

Fixes #5211
  • Loading branch information
alexr00 authored Aug 29, 2023
1 parent 69a3e04 commit 07a58cb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/github/prComment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -229,7 +229,7 @@ export class GHPRComment extends CommentBase {
contextValues.push('canDelete');
}

if (this.suggestion) {
if (this.suggestion !== undefined) {
contextValues.push('hasSuggestion');
}

Expand Down Expand Up @@ -258,7 +258,7 @@ export class GHPRComment extends CommentBase {
contextValues.push('canDelete');
}

if (this.suggestion) {
if (this.suggestion !== undefined) {
contextValues.push('hasSuggestion');
}

Expand Down Expand Up @@ -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` : '';
}
}

Expand All @@ -301,7 +301,7 @@ export class GHPRComment extends CommentBase {
return `***
Suggested change:
\`\`\`
${args[1]}
${args[2] ?? ''}
\`\`\`
***`;
});
Expand Down
2 changes: 1 addition & 1 deletion src/view/reviewCommentController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand Down

0 comments on commit 07a58cb

Please sign in to comment.