Skip to content

Commit 6c84402

Browse files
authored
Merge pull request #306 from netwrix/dev
Add detailed error logging and fallback for review post failures
2 parents fc28e14 + 4e7272c commit 6c84402

1 file changed

Lines changed: 34 additions & 17 deletions

File tree

.github/workflows/claude-documentation-reviewer.yml

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -281,24 +281,41 @@ jobs:
281281
print(f"Skipping out-of-diff suggestion: {s['path']} line {s['line']}")
282282
print(f"{len(suggestions)}/{len(all_suggestions)} suggestions are within the PR diff.")
283283
284-
review_payload = {
285-
'commit_id': head_sha,
286-
'body': review_body,
287-
'event': 'COMMENT',
288-
'comments': suggestions,
289-
}
284+
def post_review(body, comments):
285+
payload = {
286+
'commit_id': head_sha,
287+
'body': body,
288+
'event': 'COMMENT',
289+
'comments': comments,
290+
}
291+
return subprocess.run(
292+
['gh', 'api', f'repos/{repo}/pulls/{pr_number}/reviews',
293+
'-X', 'POST', '--input', '-'],
294+
input=json.dumps(payload),
295+
capture_output=True,
296+
text=True,
297+
)
290298
291-
result = subprocess.run(
292-
['gh', 'api', f'repos/{repo}/pulls/{pr_number}/reviews',
293-
'-X', 'POST', '--input', '-'],
294-
input=json.dumps(review_payload),
295-
capture_output=True,
296-
text=True,
297-
)
299+
# Try posting review with all inline suggestions.
300+
print(f"Attempting to post review with {len(suggestions)} inline suggestion(s)...")
301+
for i, s in enumerate(suggestions):
302+
print(f" [{i+1}] {s['path']} line {s.get('start_line', s['line'])}-{s['line']}")
298303
299-
if result.returncode != 0:
300-
print(f"Error posting review: {result.stderr}", file=sys.stderr)
301-
sys.exit(1)
304+
result = post_review(review_body, suggestions)
305+
306+
if result.returncode == 0:
307+
print(f"Successfully posted review with {len(suggestions)} inline suggestion(s).")
308+
else:
309+
# Log the full GitHub error response for debugging.
310+
print(f"Batch review failed (HTTP 422 or other). Falling back to body-only review.", file=sys.stderr)
311+
print(f"gh stderr: {result.stderr}", file=sys.stderr)
312+
print(f"gh stdout: {result.stdout}", file=sys.stderr)
302313
303-
print(f"Successfully posted review with {len(suggestions)} inline suggestion(s).")
314+
# Post the review body without inline suggestions so the summary is always visible.
315+
fallback = post_review(review_body, [])
316+
if fallback.returncode != 0:
317+
print(f"Fallback review also failed: {fallback.stderr}", file=sys.stderr)
318+
sys.exit(1)
319+
print("Posted review body only. Inline suggestions could not be posted.")
320+
print("See the stderr above for the GitHub API error details.")
304321
PYTHON_EOF

0 commit comments

Comments
 (0)