Skip to content

fix(hooks): CodeRabbit レビュー対応 + ポーリングロジック修正 - #11

Merged
aloekun merged 1 commit into
masterfrom
fix/post-pr-monitor-review
Apr 2, 2026
Merged

fix(hooks): CodeRabbit レビュー対応 + ポーリングロジック修正#11
aloekun merged 1 commit into
masterfrom
fix/post-pr-monitor-review

Conversation

@aloekun

@aloekun aloekun commented Apr 2, 2026

Copy link
Copy Markdown
Owner

Summary

  • CodeRabbit レビュー対応 (PR feat(hooks): Post-PR Monitor — CI・CodeRabbit自動監視 #10 の未解決3件)

    • タイムアウト処理を Windows 専用と明記 (ADR-001 準拠)
    • run_gh_quietCommand::new("gh") に統一 (cmd /c 除去)
    • debug_log 関数を削除し eprintln! に置き換え
  • ポーリングロジック修正

    • review_state: not_found でもコメント/スレッドがあれば action_required を返す
    • CI runs 空 (CI 未設定) の場合は CI チェックをスキップ (永遠 pending 防止)
  • マージ漏れ修正

    • PAT_PNPM_PUSH トリガーパターン + detect_command_type 追加

Test plan

  • cargo test — hooks-post-pr-monitor 34テスト通過
  • cargo test — check-ci-coderabbit 40テスト通過
  • pnpm build:hooks — 全 exe ビルド成功
  • pnpm push — push パイプライン (test → review → push) 通過

🤖 Generated with Claude Code

Summary by CodeRabbit

  • 新機能

    • pnpm / npm の "push" コマンド検出を追加しました。
  • 改善

    • ボットの「review in progress」コメントを判定から除外するようにし、レビュー判定ロジックを整理しました。
    • 「未検出(not_found)」でも有効な新コメントや未解決スレッドがある場合は即座にアクションが必要と判断するように変更しました。
    • CI の保留判定をより正確にし、空の実行リストによる誤判定を減らしました。
  • テスト

    • 判定ロジックとトリガー検出に関するユニットテストを追加・拡充しました。
  • その他

    • PR監視のポーリング間隔の既定値を延長しました。

@coderabbitai

coderabbitai Bot commented Apr 2, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

CodeRabbitのレビュー判定でコメントフィルタと制御フローが変更され、CI「pending」判定がci.runs非空を要求するよう厳密化。PNPM/NPMのpushコマンドがトリガーに追加され、フックのログ処理とgh呼び出しが簡素化。設定テンプレートのポーリング間隔が拡張された。

Changes

Cohort / File(s) Summary
CodeRabbit チェックロジック
​.claude/check-ci-coderabbit/src/main.rs
parse_new_commentsでCodeRabbitの「review in progress」コメントを除外。decideで先にフラグを算出し、not_foundかつ実行可能コメントがあれば早期にaction_requiredを返すよう変更。CI待機判定をci.runs非空と組み合わせるよう修正。run_checkでGH失敗時に擬似CI pendingを返す扱いを追加。build_summarynot_foundレンダリングを調整。ユニットテストを追加/更新。
フック監視(コマンド検出・実行)
​.claude/hooks-post-pr-monitor/src/main.rs
PAT_PNPM_PUSHを追加しpnpm push/pnpm run push/npm pushをデフォルトトリガーに含める。detect_command_typeを拡張。debug_logを削除してeprintln!に集約、非アクションパスを早期returnに簡素化。gh呼び出しをCommand::new("gh")で直接実行するよう変更。テスト追加/更新。
フック設定(実行間隔)
​.claude/hooks-config.toml, templates/hooks-config-python.toml, templates/hooks-config-typescript.toml
post_pr_monitorのコメント例でpnpm pushを明記し、poll_interval_secsのデフォルト説明を30120秒に更新(設定値そのものは保持)。テンプレートコメントを同期。

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed タイトルは PR の主要な変更内容を正確に反映しており、CodeRabbit レビュー対応とポーリングロジック修正の 2 つの重要な改善点を簡潔かつ明確に述べています。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
.claude/hooks-post-pr-monitor/src/main.rs (2)

89-91: 正規表現パターンに ^\s* アンカーがありません。

他のパターン(PAT_GH_PR_CREATEPAT_GIT_PUSHPAT_JJ_GIT_PUSH)はすべて ^\s* で始まっていますが、PAT_PNPM_PUSH にはこのアンカーがありません。これにより、echo pnpm push# pnpm push のようなコマンドでも誤検出する可能性があります。

♻️ 他のパターンと一貫性を持たせる修正案
-/// pnpm push / npm push / pnpm run push (パイプライン経由の push)
-const PAT_PNPM_PUSH: &str = r"(?:pnpm|npm)\s+(?:run\s+)?push(\s|$)";
+/// pnpm push / npm push / pnpm run push (パイプライン経由の push)
+const PAT_PNPM_PUSH: &str = r"^\s*(?:pnpm|npm)\s+(?:run\s+)?push(\s|$)";
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/hooks-post-pr-monitor/src/main.rs around lines 89 - 91,
PAT_PNPM_PUSH is missing the leading anchor used by the other patterns, causing
false positives (e.g., "echo pnpm push" or commented lines); update the constant
PAT_PNPM_PUSH to start with the same anchor sequence (^\s*) as PAT_GH_PR_CREATE,
PAT_GIT_PUSH, and PAT_JJ_GIT_PUSH so the regex only matches when the command
appears at the start of a line (optionally preceded by whitespace).

469-491: テストカバレッジは良好ですが、エッジケースの追加を検討してください。

正の検出ケース(pnpm pushpnpm run pushnpm push)と負のケース(pnpm build)をカバーしています。先ほど指摘した正規表現のアンカー修正後、echo pnpm push のような誤検出を防ぐテストを追加すると、パターンの堅牢性を確認できます。

🧪 追加テストの提案
#[test]
fn no_trigger_echo_pnpm_push() {
    let patterns = default_patterns();
    assert!(!is_trigger_command("echo pnpm push", &patterns));
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/hooks-post-pr-monitor/src/main.rs around lines 469 - 491, Add a
negative edge-case test to ensure commands like "echo pnpm push" don't falsely
match the trigger regex: create a test function (e.g.,
no_trigger_echo_pnpm_push) that calls default_patterns() and asserts
!is_trigger_command("echo pnpm push", &patterns); place it alongside the
existing tests (trigger_pnpm_push, trigger_pnpm_run_push, trigger_npm_push,
no_trigger_pnpm_build) to verify the anchored regex change prevents this false
positive.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.claude/hooks-post-pr-monitor/src/main.rs:
- Around line 89-91: PAT_PNPM_PUSH is missing the leading anchor used by the
other patterns, causing false positives (e.g., "echo pnpm push" or commented
lines); update the constant PAT_PNPM_PUSH to start with the same anchor sequence
(^\s*) as PAT_GH_PR_CREATE, PAT_GIT_PUSH, and PAT_JJ_GIT_PUSH so the regex only
matches when the command appears at the start of a line (optionally preceded by
whitespace).
- Around line 469-491: Add a negative edge-case test to ensure commands like
"echo pnpm push" don't falsely match the trigger regex: create a test function
(e.g., no_trigger_echo_pnpm_push) that calls default_patterns() and asserts
!is_trigger_command("echo pnpm push", &patterns); place it alongside the
existing tests (trigger_pnpm_push, trigger_pnpm_run_push, trigger_npm_push,
no_trigger_pnpm_build) to verify the anchored regex change prevents this false
positive.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e49d252e-8f28-4509-a629-eee1e79f8454

📥 Commits

Reviewing files that changed from the base of the PR and between ee998c8 and a58b41b.

⛔ Files ignored due to path filters (1)
  • .claude/post-pr-monitor-debug.log is excluded by !**/*.log
📒 Files selected for processing (2)
  • .claude/check-ci-coderabbit/src/main.rs
  • .claude/hooks-post-pr-monitor/src/main.rs

@aloekun
aloekun force-pushed the fix/post-pr-monitor-review branch from a58b41b to e5a5b4b Compare April 2, 2026 13:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.claude/check-ci-coderabbit/src/main.rs:
- Around line 381-387: The current logic treats an empty ci.runs as "no_ci",
which conflates a true no-CI repo with failures from `gh run list`; add a
distinct ci_fetch_failed state and ensure the code that calls `gh run list` sets
ci_fetch_failed on API/timeout/error instead of returning an empty runs Vec,
keep no_ci only when you’ve positively determined there are no runs, and update
the evaluation logic (symbols: ci, ci_pending, cr_pending, no_ci,
ci_fetch_failed, ci.overall, ci.runs) so that ci_pending only considers runs
when they were successfully fetched and does not skip monitoring when
ci_fetch_failed is true.
- Around line 372-378: The JSON `action` and human `summary` diverge when
cr.review_state == "not_found" and has_actionable is true; update build_summary
to consider has_actionable for the not_found case (the same condition checked
where cr.review_state and has_actionable are evaluated) so the produced summary
reflects actionable comments (e.g., treat not_found+has_actionable as "action
required" or append an actionable note) and keep the unique symbols: adjust
build_summary to inspect cr.review_state == "not_found" && has_actionable and
return a matching human-readable summary to align with the earlier
action_required return.

In @.claude/hooks-post-pr-monitor/src/main.rs:
- Around line 137-141: The detect_command_type function incorrectly returns
"pnpm push" whenever PAT_PNPM_PUSH matches, causing npm push to be
misclassified; update the logic in detect_command_type to distinguish npm vs
pnpm by checking the exact package manager token (e.g., test the command string
for "pnpm" vs "npm" or refine PAT_PNPM_PUSH to only match pnpm invocations) and
return "npm push" or "pnpm push" accordingly; apply the same fix to the
duplicate block referenced around the other instance (the block at the lines
mentioned) and add/adjust unit tests to assert both "npm push" and "pnpm push"
are returned correctly by detect_command_type.
- Around line 89-90: The code introduced a new combined default trigger constant
PAT_PNPM_PUSH but the configuration docs/sample in .claude/hooks-config.toml
were not updated; update the documentation and example to reflect the new
default trigger (PAT_PNPM_PUSH) and its combined regex (pnpm/npm (run )?push) so
users who copy the explicit settings don't miss the new pattern, and also adjust
any descriptive text that previously referenced the three separate triggers to
mention the consolidated default (see the constant name PAT_PNPM_PUSH and the
defaultization around the earlier change).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d8626f4b-439e-4fa9-afea-61b29a363178

📥 Commits

Reviewing files that changed from the base of the PR and between a58b41b and e5a5b4b.

⛔ Files ignored due to path filters (1)
  • .claude/post-pr-monitor-debug.log is excluded by !**/*.log
📒 Files selected for processing (2)
  • .claude/check-ci-coderabbit/src/main.rs
  • .claude/hooks-post-pr-monitor/src/main.rs

Comment thread .claude/check-ci-coderabbit/src/main.rs
Comment thread .claude/check-ci-coderabbit/src/main.rs
Comment on lines +89 to +90
/// pnpm push / npm push / pnpm run push (パイプライン経由の push)
const PAT_PNPM_PUSH: &str = r"^\s*(?:pnpm|npm)\s+(?:run\s+)?push(\s|$)";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

デフォルトトリガー追加に対して設定ドキュメントが未追従です

Line 97 で PAT_PNPM_PUSH をデフォルト化した一方、.claude/hooks-config.toml の説明(Line 106)とサンプル(Line 118)が旧3種のままです。明示設定をコピペした利用者が新トリガーを落とす可能性があります。

Also applies to: 97-98

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.claude/hooks-post-pr-monitor/src/main.rs around lines 89 - 90, The code
introduced a new combined default trigger constant PAT_PNPM_PUSH but the
configuration docs/sample in .claude/hooks-config.toml were not updated; update
the documentation and example to reflect the new default trigger (PAT_PNPM_PUSH)
and its combined regex (pnpm/npm (run )?push) so users who copy the explicit
settings don't miss the new pattern, and also adjust any descriptive text that
previously referenced the three separate triggers to mention the consolidated
default (see the constant name PAT_PNPM_PUSH and the defaultization around the
earlier change).

Comment thread .claude/hooks-post-pr-monitor/src/main.rs
CR#1: build_summary で not_found + actionable 時にコメント数を表示
CR#2: gh run list の API エラー時に runs 空ではなく pending (runs非空) を返す
  → API エラーとCI未設定を区別し、誤った CI スキップを防止
CR#3: hooks-config.toml のコメント/サンプルに pnpm push を追加
  → poll_interval_secs を 30 → 120 (2分) に変更
CR#4: detect_command_type で npm push を pnpm push と区別

テスト: 77 (36 + 41) パス

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant