From 8930f9f4950b267bc3509885258ca83b7e253e55 Mon Sep 17 00:00:00 2001 From: Harjot Gill Date: Tue, 18 Apr 2023 17:52:06 -0700 Subject: [PATCH] refactor review comment posting (#200) --- dist/index.js | 34 ++++++++++++---------------------- src/commenter.ts | 35 ++++++++++++++--------------------- 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7eef6b25..21dd593c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3655,30 +3655,20 @@ ${COMMENT_TAG}`; } if (!found) { _actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Creating new review comment for ${comment.path}:${comment.start_line}-${comment.end_line}: ${comment.message}`); + const commentData = { + owner: repo.owner, + repo: repo.repo, + pull_number, + commit_id, + body: comment.message, + path: comment.path, + line: comment.end_line + }; if (comment.start_line !== comment.end_line) { - await _octokit_js__WEBPACK_IMPORTED_MODULE_2__/* .octokit.pulls.createReviewComment */ .K.pulls.createReviewComment({ - owner: repo.owner, - repo: repo.repo, - pull_number, - commit_id, - body: comment.message, - path: comment.path, - line: comment.end_line, - start_side: 'RIGHT', - start_line: comment.start_line - }); - } - else { - await _octokit_js__WEBPACK_IMPORTED_MODULE_2__/* .octokit.pulls.createReviewComment */ .K.pulls.createReviewComment({ - owner: repo.owner, - repo: repo.repo, - pull_number, - commit_id, - body: comment.message, - path: comment.path, - line: comment.end_line - }); + commentData.start_side = 'RIGHT'; + commentData.start_line = comment.start_line; } + await _octokit_js__WEBPACK_IMPORTED_MODULE_2__/* .octokit.pulls.createReviewComment */ .K.pulls.createReviewComment(commentData); } commentCounter++; _actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Comment ${commentCounter}/${this.reviewCommentsBuffer.length} posted`); diff --git a/src/commenter.ts b/src/commenter.ts index 852b375f..2ee42802 100644 --- a/src/commenter.ts +++ b/src/commenter.ts @@ -184,29 +184,22 @@ ${COMMENT_TAG}` core.info( `Creating new review comment for ${comment.path}:${comment.start_line}-${comment.end_line}: ${comment.message}` ) + const commentData: any = { + owner: repo.owner, + repo: repo.repo, + pull_number, + commit_id, + body: comment.message, + path: comment.path, + line: comment.end_line + } + if (comment.start_line !== comment.end_line) { - await octokit.pulls.createReviewComment({ - owner: repo.owner, - repo: repo.repo, - pull_number, - commit_id, - body: comment.message, - path: comment.path, - line: comment.end_line, - start_side: 'RIGHT', - start_line: comment.start_line - }) - } else { - await octokit.pulls.createReviewComment({ - owner: repo.owner, - repo: repo.repo, - pull_number, - commit_id, - body: comment.message, - path: comment.path, - line: comment.end_line - }) + commentData.start_side = 'RIGHT' + commentData.start_line = comment.start_line } + + await octokit.pulls.createReviewComment(commentData) } commentCounter++