about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndrew Dolgov <fox@fakecake.org>2026-06-22 18:39:17 +0300
committerAndrew Dolgov <fox@fakecake.org>2026-06-22 18:39:17 +0300
commit74e1d273fe017060e7610cc9b67c136d9d6b5a3a (patch)
treeba6a9924b71b438e828d9a429eb6151f8a404c66
parentf83b210bc4cec556b82b0a6bfa1900830455132b (diff)
downloadthe-epube-74e1d273fe017060e7610cc9b67c136d9d6b5a3a.tar.gz
the-epube-74e1d273fe017060e7610cc9b67c136d9d6b5a3a.tar.xz
debug
-rw-r--r--review_mr.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/review_mr.py b/review_mr.py
index acf57d6..2a8c0c6 100644
--- a/review_mr.py
+++ b/review_mr.py
@@ -355,15 +355,16 @@ def _fetch_position_metadata(
                 "position_type": "text",
             }
         if lookup:
+            print(f"  (Using /positions endpoint: {len(lookup)} entries)", file=sys.stderr)
             return lookup
-    except requests.HTTPError:
-        pass  # Fall through to MR-level fallback
+    except requests.HTTPError as exc:
+        print(f"  (positions endpoint failed: {exc.response.status_code} {exc.response.text[:200]})", file=sys.stderr)
 
     # Fallback: get MR info and parse diff text for line numbers
     mr_url = f"{server_url}/api/v4/projects/{project_id}/merge_requests/{mr_iid}"
     mr = _api_get(mr_url, {"PRIVATE-TOKEN": token})
     sha = mr.get("sha", "")
-    print("  (Using MR-level SHA as fallback for position metadata)", file=sys.stderr)
+    print(f"  (Fallback: using MR-level SHA {sha[:8]}...)", file=sys.stderr)
 
     diffs_url = (
         f"{server_url}/api/v4/projects/{project_id}/merge_requests/{mr_iid}/diffs"
@@ -414,6 +415,10 @@ def post_annotations(
 
     print("  Fetching diff position metadata...")
     pos_lookup = _fetch_position_metadata(project_id, mr_iid, token, server_url)
+    print(f"    Position entries: {len(pos_lookup)}", file=sys.stderr)
+    # Show sample positions
+    for i, (key, val) in enumerate(list(pos_lookup.items())[:3]):
+        print(f"    Sample: {key} -> {val}", file=sys.stderr)
 
     posted = 0
     for ann in annotations:
@@ -423,22 +428,31 @@ def post_annotations(
             continue
 
         # Reconstruct full position dict from the lookup entry + key info
-        # We need to extract old_path, new_path, old_line, new_line from the key
-        # Since pos_lookup values don't include paths, rebuild from lookup
         for key, pos_data in pos_lookup.items():
             if pos_data is pos:
                 old_path, new_path, old_line, new_line = key
+                position = {
+                    **pos_data,
+                    "old_path": old_path,
+                    "new_path": new_path,
+                    "old_line": old_line,
+                    "new_line": new_line,
+                }
                 payload = {
                     "body": ann.message,
-                    "position": {
-                        **pos_data,
-                        "old_path": old_path,
-                        "new_path": new_path,
-                        "old_line": old_line,
-                        "new_line": new_line,
-                    },
+                    "position": position,
                 }
-                _api_post(url, {"PRIVATE-TOKEN": token}, payload)
+                print(f"    Posting: file={ann.file} line={ann.line} pos={position}", file=sys.stderr)
+                result = _api_post(url, {"PRIVATE-TOKEN": token}, payload)
+                # Check if the comment was created with a position
+                has_position = result.get("position") is not None
+                is_system = result.get("system") is True
+                if not has_position or is_system:
+                    print(f"    WARNING: GitLab returned comment WITHOUT position field "
+                          f"(has_position={has_position}, system={is_system}). "
+                          f"This means the inline annotation was NOT created. "
+                          f"The position may be invalid or the token lacks permissions.",
+                          file=sys.stderr)
                 print(f"  Annotated {ann.file}:{ann.line}")
                 posted += 1
                 break