From 1a48639557c82f0ba8d1d42c6721f654b230adcc Mon Sep 17 00:00:00 2001 From: atomoh Date: Thu, 26 Nov 2026 02:01:36 +0000 Subject: [PATCH] Pipe paginated review comments to jq when publishing the required check --- .github/workflows/pr-review.yml | 4 ++-- scripts/v2/test_claude_review.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-review.yml b/.github/workflows/pr-review.yml index 673d8c4f..31b8a574 100644 --- a/.github/workflows/pr-review.yml +++ b/.github/workflows/pr-review.yml @@ -212,8 +212,8 @@ jobs: fi printf '\n## Claude Code Review\n\n**Status: %s** — %s\n\nHEAD %s. [Bedrock review details](%s/%s/actions/runs/%s).\n' \ "$status" "$reason" "$HEAD" "$GITHUB_SERVER_URL" "$GITHUB_REPOSITORY" "$GITHUB_RUN_ID" > "$RUNNER_TEMP/review.md" - comment=$(gh api --paginate --slurp "repos/$GITHUB_REPOSITORY/issues/$PR/comments" \ - --jq '[.[][] | select(.user.login == "github-actions[bot]" and (.body | startswith("")))] | last | .id // empty') + comment=$(gh api --paginate --slurp "repos/$GITHUB_REPOSITORY/issues/$PR/comments?per_page=100" | + jq -r '[.[][] | select(.user.login == "github-actions[bot]" and (.body | startswith("")))] | last | .id // empty') if [[ -n "$comment" ]]; then jq -Rs '{body: .}' "$RUNNER_TEMP/review.md" | \ gh api --silent -X PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$comment" --input - diff --git a/scripts/v2/test_claude_review.py b/scripts/v2/test_claude_review.py index c5bdfe0d..f975d74b 100644 --- a/scripts/v2/test_claude_review.py +++ b/scripts/v2/test_claude_review.py @@ -74,6 +74,26 @@ def git(*args): validate(dict(result, **change), index, head) self.assertEqual(paths, {"plain.ts", ":(glob)*.ts", "spaced ü.ts"}) + def test_publisher_selects_the_last_bot_comment_across_pages(self): + workflow = yaml.safe_load((ROOT / ".github/workflows/pr-review.yml").read_text()) + script = workflow["jobs"]["gate"]["steps"][0]["run"] + lookup = script.split("comment=$(", 1)[1].split(")\n", 1)[0] + # Validate the actual gh flag combination without authenticating or posting. + # gh rejects --slurp with --jq even when there are no comments. + self.assertIn("gh api --paginate --slurp", lookup) + self.assertNotIn("--jq", lookup) + jq = lookup.split("|\n", 1)[1].strip() + def select(pages): + return subprocess.run(["bash", "-euc", jq], input=json.dumps(pages), + text=True, capture_output=True, check=True).stdout.strip() + marker = "" + def comment(identifier, author, body): + return {"id": identifier, "user": {"login": author}, "body": body} + self.assertEqual(select([[]]), "") + self.assertEqual(select([[comment(1, "github-actions[bot]", marker)], + [comment(2, "reviewer", marker), comment(3, "github-actions[bot]", marker), + comment(4, "github-actions[bot]", "other check")]]), "3") + def test_action_uses_bedrock_and_all_results_gate_the_protected_check(self): jobs = yaml.safe_load((ROOT / ".github/workflows/pr-review.yml").read_text())["jobs"] model = jobs["claude"]