Skip to content

Commit 07d06bb

Browse files
style: Condense printing of trailing hunk lines
This commit makes a minor stylistic refactoring in the `scripts/gha/get_pr_review_comments.py` script. When displaying the trailing lines of a diff hunk (for `--context-lines > 0`, after the header line is potentially printed and removed from the `hunk_lines` list), the script now uses `print("\n".join(hunk_lines[-args.context_lines:]))` instead of explicitly creating a sub-list and then looping through it with `print()` for each line. This change achieves the same visual output (printing a newline if `hunk_lines` becomes empty after header removal) but is more concise.
1 parent 9312a0c commit 07d06bb

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

scripts/gha/get_pr_review_comments.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,10 @@ def main():
205205
hunk_lines = hunk_lines[1:] # Modify list in place for remaining operations
206206

207207
# Proceed with the (potentially modified) hunk_lines
208-
if hunk_lines: # Check if there's anything left to print
209-
# args.context_lines is > 0 here
210-
actual_trailing_lines = hunk_lines[-args.context_lines:]
211-
print("\n".join(actual_trailing_lines))
212-
# If hunk_lines is empty here (e.g. only contained a header that was removed), nothing more is printed.
208+
# If hunk_lines is empty here (e.g. original hunk was only a header that was removed),
209+
# hunk_lines[-args.context_lines:] will be [], and "\n".join([]) is "",
210+
# so print("") will effectively print a newline. This is acceptable.
211+
print("\n".join(hunk_lines[-args.context_lines:]))
213212
else: # diff_hunk was None or empty
214213
print("(No diff hunk available for this comment)")
215214
print("```") # End of Markdown code block

0 commit comments

Comments
 (0)