fix(post): anchor inline review comments via new_position (Gitea 1.26.x)

Gitea 1.26.x's POST /pulls/{i}/reviews does NOT honor the line/side fields
used by newer Gitea — it silently drops them, leaving the comment unpositioned.
Gitea then renders a file-level review comment on EVERY diff line of the file,
so a 5-finding review on a 25-line diff showed ~125 comment blocks in the
Files Changed view (the flood reported on canalhandia PR #2).

The 1.26 schema anchors inline review comments with new_position (line in the
post-change file) + old_position: 0. f["line"] is already a validated
post-change (RIGHT-side) line from split_findings, so it maps directly to
new_position. Verified: new_position=98 -> position=98 + populated diff_hunk
(positioned, renders on line 98 only); the old line/side form -> position=0,
empty diff_hunk (unpositioned).

49 tests pass (no test asserted the POST payload shape).

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Marcos
2026-08-18 00:54:13 +00:00
parent c7c6c3edd2
commit 4129f217fa
+10 -5
View File
@@ -626,15 +626,20 @@ def post_inline_review(
) -> None:
"""Post a review with a summary body AND positional inline comments.
Each anchored finding becomes one entry in `comments`:
{path, side:"RIGHT", line, body}. The body carries the ```suggestion
fence when the model produced replacement code.
Each anchored finding becomes one entry in `comments`. Gitea 1.26.x anchors
inline review comments with `new_position` (the line in the POST-change file)
+ `old_position: 0` — the `line`/`side` fields used by newer Gitea are NOT
honored here and silently leave the comment unpositioned (Gitea then renders
a file-level comment on EVERY diff line of the file, which is the flood we
hit). `f["line"]` is already a validated post-change (RIGHT-side) line from
`split_findings`, so it maps directly to `new_position`. The body carries the
```suggestion fence when the model produced replacement code.
"""
comments = [
{
"path": f["path"],
"side": "RIGHT",
"line": f["line"],
"new_position": f["line"],
"old_position": 0,
"body": inline_comment_body(f),
}
for f in anchored