Skip to content

Commit 94417e7

Browse files
style: Refactor hunk printing to use join for conciseness
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`), the script now uses `print("\n".join(lines))` instead of a `for` loop with `print()` for each line. This change achieves the same visual output but is more concise and Pythonic for joining and printing a list of strings as multiple lines.
1 parent 5a4010f commit 94417e7

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

scripts/gha/get_pr_review_comments.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def main():
122122
return
123123

124124
latest_created_at_obj = None
125+
processed_comments_count = 0
125126
print("# Review Comments\n\n")
126127
for comment in comments:
127128
# This replaces the previous status/skip logic for each comment
@@ -176,6 +177,8 @@ def main():
176177
if not body:
177178
continue
178179

180+
processed_comments_count += 1
181+
179182
diff_hunk = comment.get("diff_hunk")
180183
html_url = comment.get("html_url", "N/A")
181184
comment_id = comment.get("id")
@@ -196,20 +199,16 @@ def main():
196199
print(diff_hunk)
197200
else: # User wants N lines of context (args.context_lines > 0)
198201
hunk_lines = diff_hunk.split('\n')
199-
header_printed_this_time = False
200202
if hunk_lines and hunk_lines[0].startswith("@@ "):
201203
print(hunk_lines[0])
202-
hunk_lines = hunk_lines[1:] # Operate on the rest of the hunk
203-
header_printed_this_time = True # Flag that header was output
204-
205-
if hunk_lines: # If there are lines left after potentially removing header
206-
lines_to_print_count = args.context_lines
207-
actual_trailing_lines = hunk_lines[-lines_to_print_count:]
208-
for line_content in actual_trailing_lines:
209-
print(line_content)
210-
elif not header_printed_this_time :
211-
pass # Hunk was empty or only a header, already handled by outer 'else' or header print
212-
204+
hunk_lines = hunk_lines[1:] # Modify list in place for remaining operations
205+
206+
# Proceed with the (potentially modified) hunk_lines
207+
if hunk_lines: # Check if there's anything left to print
208+
# args.context_lines is > 0 here
209+
actual_trailing_lines = hunk_lines[-args.context_lines:]
210+
print("\n".join(actual_trailing_lines))
211+
# If hunk_lines is empty here (e.g. only contained a header that was removed), nothing more is printed.
213212
else: # diff_hunk was None or empty
214213
print("(No diff hunk available for this comment)")
215214
print("```") # End of Markdown code block
@@ -218,6 +217,8 @@ def main():
218217
print(body)
219218
print("\n---")
220219

220+
sys.stderr.write(f"\nPrinted {processed_comments_count} comments to stdout.\n")
221+
221222
if latest_created_at_obj:
222223
try:
223224
# Ensure it's UTC before adding timedelta, then format

0 commit comments

Comments
 (0)