fix: コメント付き PR で初回向けの reason 文言が出るのを直す(#116) - #117
Merged
Conversation
reason=assign / review_requested の通知でフォローアップ文言に切り替える 判定を Subject#commented?(latest_comment_url が subject.url と異なるか) だけに頼っていたため、コメントの付いた PR でも「アサインされました」の ままになることがあった。 latest_comment_url は通知を発生させたイベント側を反映することがあり、 コメント済みでも push・レビュー・アサイン変更が起点の通知では subject.url に戻る。またレビューコメントが反映されないケースもあり、「コメントが無い」 側の確定には使えない。 本文表示のためにどのみち取得している subject 本体(PR / Issue)の レスポンスにはコメント数が含まれるので、これを判定に併用する。 Subject#commented? が false のとき comment_url は PR / Issue 自体を指す ため、追加の API 呼び出しは発生しない。 コメント 0 件でレビューだけが付いた PR は件数に現れないため従来どおりの 文言になるが、レビューの有無の取得には追加 API が必要なため許容する。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WkcsCNsBVPds1SktQ5cFSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close #116
症状
コメントの付いている PR でも、reason=assign の通知が初回向け文言「アサインされました」のままになる。#104 で入れたフォローアップ文言(「担当している PR/Issue に動きがありました」)に切り替わらない。
原因
切り替え条件の
Subject#commented?は「latest_comment_urlがsubject.urlと異なる」ことをコメントありの根拠にしている。しかしこの判定は真になる側にしか使えない:latest_comment_urlは通知を発生させたイベント側を反映することがあり、コメント済みのスレッドでも push・レビュー・アサイン変更が起点の通知ではsubject.urlに戻るどちらでも
commented?が false になり、初回向け文言に落ちる。#104 は「latest_comment_urlはスレッドの現在の最新コメントを指す」という前提だったが、その前提が「コメントが無い」側の確定には使えなかった。対応
latest_comment_url単独の判定をやめ、本文表示のためにどのみち取得している subject 本体のコメント数を併用する。Github::Usecase#build_messageは本文のためにsubject.comment_urlを毎回 GET している。commented?が false のとき、この URL は PR / Issue オブジェクト自体を指す(comment_urlのフォールバック仕様)。PR レスポンスにはcomments(会話タブ)とreview_comments(レビュー)、Issue レスポンスにはcommentsが含まれるので、この取得済みレスポンスから件数を拾えばスレッドにコメントがあるかを判定できる。追加の API 呼び出しは発生しない。Subject#commented?が true のときは取得先が実コメントで件数フィールドを持たないが、その場合は先に true が確定するので影響しない。変更点
src/github/models.crCommentにcomments/review_comments(nilable)と#commented?を追加。コメントと subject 本体の両方をこのクラスで受けている旨をコメントに追記Notification#reason_message/#pretextが取得済みCommentを任意引数で受け取り、新設の#followup?で切り替えを判定Subject#commented?の doc に、偽でもコメントが無いとは限らない(片道の判定である)ことを追記src/github/usecase.cr:build_messageで取得済みcommentをpretextに渡すComment#commented?単体、usecase 経由の pretext を追加確認していないこと
CloudWatch Logs に出力されている実ペイロードで、上記 2 つの原因候補のどちらが起きているかまでは確定できていない(AWS の認証が切れていて本セッションからログを参照できなかった)。ただし修正はどちらのケースでも同じ経路で解消するため、原因の特定を待たずに入れられる内容になっている。
既知の制約(スコープ外)
comments/review_commentsとも 0 のため、従来どおり「アサインされました」になる。レビューの有無は PR レスポンスに含まれず追加 API が必要なため今回は許容するreview_requestedも同じテーブルと判定を使うため、同種の取りこぼしが同時に改善されるテスト
CI(format / ameba / spec)に委ねている。この環境には Crystal ツールチェインが無く、ネットワーク制限でインストールもできなかったため、ローカルでの spec 実行はしていない。
Generated by Claude Code