about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-22 19:04:18 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-22 19:04:18 +0300
commitfde5709c464b3a754b69a778c859c4a48700ce65 (patch)
treeb477c8665e1237e219b875ea2c07bf4709d17a0c
parentf997b5aa52f41749d3d011c089969592154e2de4 (diff)
downloadthe-epube-fde5709c464b3a754b69a778c859c4a48700ce65.tar.gz
the-epube-fde5709c464b3a754b69a778c859c4a48700ce65.tar.xz
more updates
-rw-r--r--review_mr.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/review_mr.py b/review_mr.py
index 4fe5b27..457497b 100644
--- a/review_mr.py
+++ b/review_mr.py
@@ -281,15 +281,19 @@ def post_comment(
     print("Plain review comment posted.")
 
 
-def _build_positions_from_diff(diffs: list[dict], base_sha: str, head_sha: str) -> dict[tuple, dict]:
+def _build_positions_from_diff(
+    diffs: list[dict], base_sha: str, head_sha: str, start_sha: str
+) -> dict[tuple, dict]:
     """Build position lookup from diff entries by parsing hunk headers.
 
     Returns a mapping of (old_path, new_path, old_line, new_line) -> position dict.
+    Each position includes base_sha, head_sha, and start_sha.
     """
     import re as _re
 
     hunk_re = _re.compile(r"^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@")
     lookup: dict[tuple, dict] = {}
+    base = {"base_sha": base_sha, "head_sha": head_sha, "start_sha": start_sha, "position_type": "text"}
 
     for d in diffs:
         old_path = d.get("old_path", "")
@@ -308,19 +312,11 @@ def _build_positions_from_diff(diffs: list[dict], base_sha: str, head_sha: str)
                 continue
             if line.startswith("+"):
                 key = (old_path, new_path, None, new_line)
-                lookup[key] = {
-                    "base_sha": base_sha,
-                    "head_sha": head_sha,
-                    "position_type": "text",
-                }
+                lookup[key] = {**base, "old_line": None, "new_line": new_line}
                 new_line += 1
             elif line.startswith(" "):
                 key = (old_path, new_path, new_line, new_line)
-                lookup[key] = {
-                    "base_sha": base_sha,
-                    "head_sha": head_sha,
-                    "position_type": "text",
-                }
+                lookup[key] = {**base, "old_line": new_line, "new_line": new_line}
                 new_line += 1
             # removal lines (-) have no new_line, skip
 
@@ -366,13 +362,14 @@ def _fetch_position_metadata(
     diff_refs = mr.get("diff_refs", {})
     base_sha = diff_refs.get("base_sha", mr.get("sha", ""))
     head_sha = diff_refs.get("head_sha", mr.get("sha", ""))
-    print(f"  (Fallback: base_sha={base_sha[:8]}... head_sha={head_sha[:8]}...)", file=sys.stderr)
+    start_sha = diff_refs.get("start_sha", base_sha)
+    print(f"  (Fallback: base={base_sha[:8]}... head={head_sha[:8]}... start={start_sha[:8]}...)", file=sys.stderr)
 
     diffs_url = (
         f"{server_url}/api/v4/projects/{project_id}/merge_requests/{mr_iid}/diffs"
     )
     diffs = _api_get(diffs_url, {"PRIVATE-TOKEN": token})
-    lookup = _build_positions_from_diff(diffs, base_sha, head_sha)
+    lookup = _build_positions_from_diff(diffs, base_sha, head_sha, start_sha)
     return lookup
 
 
@@ -437,10 +434,9 @@ def post_annotations(
                     **pos_data,
                     "old_path": old_path,
                     "new_path": new_path,
+                    "old_line": old_line,
                     "new_line": new_line,
                 }
-                if old_line is not None:
-                    position["old_line"] = old_line
                 payload = {
                     "body": ann.message,
                     "position": position,