Skip to content

feat: 差分に対してsingle commentを投稿できるようにする - #193

Merged
kyu08 merged 7 commits into
mainfrom
107
Sep 25, 2026
Merged

kyu08 merged 7 commits into
mainfrom
107

Conversation

@kyu08

@kyu08 kyu08 commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

概要

:FudeReviewComment / :FudeReviewSuggest の <CR> で、pending reviewに追加するか、single commentとして即時公開するかを選べるようにする。これまではpending reviewへの追加しかできなかった。

Closes #107

変更内容

  • <CR> 押下時に vim.ui.select で Add single comment (post now) / Start a review (pending) を選ぶようにした
    • 選択はフロートを閉じる前に行い、キャンセルしたら入力に戻る。閉じてから選ばせると、キャンセル時に本文が消えるため
  • pending reviewがある間はselectを出さず、そのままpending reviewに追加する
    • GitHubはpending reviewを持つユーザーのsingle comment(POST /pulls/{pr}/comments)を422で拒否するため、選択肢が1つしか残らない
    • 判定は <CR> 押下時に行う。フロートを開いている間にauto-reloadでpending reviewが検出されるケースに追従するため
    • pending_review_id に加えて pending_comments が空でないかも見る(sync.has_pending_review)。最初のpending reviewの作成中は pending_comments だけが先に埋まり、IDは応答が返るまで入らないため
  • single commentの投稿は comments/sync.lua の create_single_comment に追加し、既存だが未使用だった gh.create_comment / gh.create_comment_range を使った
    • commit_idはpending reviewと同じくHEADを使う。commit scope中はそのcommitに付く
  • open_comment_input の新オプション pick_submit_kind を渡すのはGitHubモードの2コマンドだけで、localモード・overview・reply・editの挙動は変えていない

テスト計画

  • make all(lint、format-check、全テスト)がパスする
  • 新規テスト追加: tests/fude/ui_spec.lua, tests/fude/comments_spec.lua, tests/fude/comments_drafts_spec.lua, tests/fude/sync_integration_spec.lua

備考

  • :FudeReviewStart 直後など、GitHub上のpending reviewをまだ取得していない間はsingle commentを選べてしまう。この場合はAPIの422がERROR通知で表面化する
  • single commentの投稿がAPIで失敗すると、入力した本文は失われる(保存済みのdraftは残る)。既存のpending保存の失敗時と同じ扱いにしている

Generated with Claude Code

Copilot AI lite review requested due to automatic review settings September 25, 2026 09:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Resolve draft-removal races, stale-session callbacks, pending-comment loss, and the documentation inconsistency.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds support for posting GitHub diff comments either as pending review comments or immediately as single comments.

Changes:

  • Adds submission-method selection and pending-review handling.
  • Adds single-comment API and draft integration.
  • Updates tests and documentation.
File Summary
tests/​fude/​ui_spec.lua Tests submission UI behavior.
tests/​fude/​sync_integration_spec.lua Tests API synchronization.
tests/​fude/​comments_spec.lua Tests submission options.
tests/​fude/​comments_drafts_spec.lua Tests posting and draft handling.
README.md Updates usage documentation.
lua/​fude/​ui.lua Adds submission-method selection UI.
lua/​fude/​comments/​sync.lua Implements single-comment API handling.
lua/​fude/​comments/​data.lua Defines submission options.
lua/​fude/​comments.lua Adds submission and single-comment workflows.
doc/​fude.txt Updates detailed help documentation.
CLAUDE.md Updates architecture documentation.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lua/fude/comments.lua Outdated
Comment thread lua/fude/comments/sync.lua
Copilot AI review requested due to automatic review settings September 25, 2026 10:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Two unresolved moderate issues remain in callback/session safety and concurrent refresh handling.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)

Comment thread lua/fude/comments.lua
Comment on lines +155 to +164
local draft_snapshot = drafts.get(draft_key)
sync.create_single_comment(rel_path, start_line, end_line, body, function(err)
if err then
vim.notify("fude.nvim: Failed to post " .. label:lower() .. ": " .. err, vim.log.levels.ERROR)
return
end
drafts.remove_if_unchanged(draft_key, draft_snapshot)
ui.refresh_extmarks()
vim.notify("fude.nvim: " .. label .. " posted", vim.log.levels.INFO)
end)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

refresh_extmarks() は古いデータを持ち込まず、その時点の config.state と現在のバッファから描き直すだけなので、セッションが変わった後に走っても新しいセッションの状態で同じ表示を再描画するだけになる。セッションがない場合は state.active のガードで抜ける。draft削除も元のPR固有のkeyに対する操作なので、新しいセッションには影響しない。このため対応は見送る。

@kyu08
kyu08 marked this pull request as ready for review September 25, 2026 10:33
@kyu08
kyu08 requested a review from flexphere as a code owner September 25, 2026 10:33
@kyu08
kyu08 merged commit fea50a2 into main Sep 25, 2026
10 checks passed
@kyu08
kyu08 deleted the 107 branch September 25, 2026 10:34
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.

差分に対してsingle commentを投稿できるようにする

2 participants