Skip to content
This repository was archived by the owner on Mar 6, 2024. It is now read-only.

Commit c9e8cec

Browse files
authored
single line comments (#134)
1 parent 4129f5a commit c9e8cec

File tree

3 files changed

+62
-32
lines changed

3 files changed

+62
-32
lines changed

action.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,15 @@ inputs:
187187
188188
Your review must consist of comments in the below format
189189
with a separator between review comments. The format consists of
190-
line number ranges and review comments applicable for that line
191-
number range. Any other commentary outside of this format will be ignored
192-
and will not be read by the parser -
190+
line number range and review comment applicable for that line
191+
number range. Any other commentary outside of this format will be ignored
192+
and will not be read by the parser. It's important that line number
193+
ranges for each review must be within line number range of new_hunks.
194+
Don't echo back the code provided to you as the
195+
line number range is sufficient to map your comment to the relevant code
196+
section in GitHub. You can make multiple comments for each hunk and
197+
suggest new code that can replace code at those line number ranges.
198+
193199
<start_line_number_in_new_hunk>-<end_line_number_in_new_hunk>:
194200
<your review>
195201
---
@@ -200,11 +206,6 @@ inputs:
200206
LGTM!
201207
---
202208
203-
It's important that line number ranges for each review must
204-
be sub range of line number range of new_hunks. Don't echo back the
205-
code provided to you as the line number range is sufficient to map
206-
your comment to the relevant code section in GitHub.
207-
208209
Reflect on the provided code at least 3 times and identify any
209210
bug risks or provide improvement suggestions in these changes.
210211
You will point out potential issues such as security, logic errors,

dist/index.js

Lines changed: 27 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/commenter.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,31 @@ ${tag}`
173173
core.info(
174174
`Creating new review comment for ${path}:${start_line}-${end_line}: ${message}`
175175
)
176-
await octokit.pulls.createReviewComment({
177-
owner: repo.owner,
178-
repo: repo.repo,
179-
pull_number,
180-
body: message,
181-
commit_id,
182-
path,
183-
line: end_line,
184-
start_line,
185-
start_side: 'RIGHT'
186-
})
176+
// if start_line is same as end_line, it's a single line comment
177+
// otherwise it's a multi-line comment
178+
if (start_line === end_line) {
179+
await octokit.pulls.createReviewComment({
180+
owner: repo.owner,
181+
repo: repo.repo,
182+
pull_number,
183+
body: message,
184+
commit_id,
185+
path,
186+
line: end_line
187+
})
188+
} else {
189+
await octokit.pulls.createReviewComment({
190+
owner: repo.owner,
191+
repo: repo.repo,
192+
pull_number,
193+
body: message,
194+
commit_id,
195+
path,
196+
line: end_line,
197+
start_line,
198+
start_side: 'RIGHT'
199+
})
200+
}
187201
}
188202
} catch (e) {
189203
core.warning(
@@ -256,7 +270,7 @@ ${COMMENT_REPLY_TAG}
256270
(comment: any) =>
257271
comment.path === path &&
258272
comment.body !== '' &&
259-
((comment.start_line &&
273+
((comment.start_line !== undefined &&
260274
comment.start_line >= start_line &&
261275
comment.line <= end_line) ||
262276
comment.line === end_line)

0 commit comments

Comments
 (0)