Skip to content

Commit

Permalink
Make sure to skip comments on lines that aren't in the PR diff
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Feb 7, 2022
1 parent 70df149 commit 76cce86
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions review.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,35 +356,35 @@ def make_review(diagnostics, diff_lookup, offset_lookup):
notes=diagnostic.get("Notes", []),
)

rel_path = try_relative(diagnostic_message["FilePath"])
rel_path = str(try_relative(diagnostic_message["FilePath"]))
# diff lines are 1-indexed
source_line = 1 + find_line_number_from_offset(
offset_lookup[diagnostic_message["FilePath"]],
diagnostic_message["FileOffset"],
)

try:
comments.append(
{
"path": str(rel_path),
"body": comment_body,
"side": "RIGHT",
"line": end_line,
# "position": diff_lookup[rel_path][source_line],
}
)
# If this is a multiline comment, we need a couple more bits:
if end_line != source_line:
comments[-1].update(
{
"start_side": "RIGHT",
"start_line": source_line,
}
)
except KeyError:
if rel_path not in diff_lookup or end_line not in diff_lookup[rel_path]:
print(
f"WARNING: Skipping comment for file '{rel_path}' not in PR changeset. Comment body is:\n{comment_body}"
)
continue

comments.append(
{
"path": rel_path,
"body": comment_body,
"side": "RIGHT",
"line": end_line,
}
)
# If this is a multiline comment, we need a couple more bits:
if end_line != source_line:
comments[-1].update(
{
"start_side": "RIGHT",
"start_line": source_line,
}
)

review = {
"body": "clang-tidy made some suggestions",
Expand Down

0 comments on commit 76cce86

Please sign in to comment.