diff --git a/action.yml b/action.yml index e6c1612e..418d4121 100644 --- a/action.yml +++ b/action.yml @@ -187,9 +187,15 @@ inputs: Your review must consist of comments in the below format with a separator between review comments. The format consists of - line number ranges and review comments applicable for that line - number range. Any other commentary outside of this format will be ignored - and will not be read by the parser - + line number range and review comment applicable for that line + number range. Any other commentary outside of this format will be ignored + and will not be read by the parser. It's important that line number + ranges for each review must be within line number range of new_hunks. + Don't echo back the code provided to you as the + line number range is sufficient to map your comment to the relevant code + section in GitHub. You can make multiple comments for each hunk and + suggest new code that can replace code at those line number ranges. + -: --- @@ -200,11 +206,6 @@ inputs: LGTM! --- - It's important that line number ranges for each review must - be sub range of line number range of new_hunks. Don't echo back the - code provided to you as the line number range is sufficient to map - your comment to the relevant code section in GitHub. - Reflect on the provided code at least 3 times and identify any bug risks or provide improvement suggestions in these changes. You will point out potential issues such as security, logic errors, diff --git a/dist/index.js b/dist/index.js index f0be75b4..ccdea437 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2439,17 +2439,32 @@ ${tag}`; } if (!found) { _actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Creating new review comment for ${path}:${start_line}-${end_line}: ${message}`); - await octokit.pulls.createReviewComment({ - owner: repo.owner, - repo: repo.repo, - pull_number, - body: message, - commit_id, - path, - line: end_line, - start_line, - start_side: 'RIGHT' - }); + // if start_line is same as end_line, it's a single line comment + // otherwise it's a multi-line comment + if (start_line === end_line) { + await octokit.pulls.createReviewComment({ + owner: repo.owner, + repo: repo.repo, + pull_number, + body: message, + commit_id, + path, + line: end_line + }); + } + else { + await octokit.pulls.createReviewComment({ + owner: repo.owner, + repo: repo.repo, + pull_number, + body: message, + commit_id, + path, + line: end_line, + start_line, + start_side: 'RIGHT' + }); + } } } catch (e) { @@ -2508,7 +2523,7 @@ ${COMMENT_REPLY_TAG} const comments = await this.list_review_comments(pull_number); return comments.filter((comment) => comment.path === path && comment.body !== '' && - ((comment.start_line && + ((comment.start_line !== undefined && comment.start_line >= start_line && comment.line <= end_line) || comment.line === end_line)); diff --git a/src/commenter.ts b/src/commenter.ts index 4793d5b3..009084d5 100644 --- a/src/commenter.ts +++ b/src/commenter.ts @@ -173,17 +173,31 @@ ${tag}` core.info( `Creating new review comment for ${path}:${start_line}-${end_line}: ${message}` ) - await octokit.pulls.createReviewComment({ - owner: repo.owner, - repo: repo.repo, - pull_number, - body: message, - commit_id, - path, - line: end_line, - start_line, - start_side: 'RIGHT' - }) + // if start_line is same as end_line, it's a single line comment + // otherwise it's a multi-line comment + if (start_line === end_line) { + await octokit.pulls.createReviewComment({ + owner: repo.owner, + repo: repo.repo, + pull_number, + body: message, + commit_id, + path, + line: end_line + }) + } else { + await octokit.pulls.createReviewComment({ + owner: repo.owner, + repo: repo.repo, + pull_number, + body: message, + commit_id, + path, + line: end_line, + start_line, + start_side: 'RIGHT' + }) + } } } catch (e) { core.warning( @@ -256,7 +270,7 @@ ${COMMENT_REPLY_TAG} (comment: any) => comment.path === path && comment.body !== '' && - ((comment.start_line && + ((comment.start_line !== undefined && comment.start_line >= start_line && comment.line <= end_line) || comment.line === end_line)