@devries-cameron20 / t3code-1 / commits / 3a0bcba00a
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(shared): GitLab merge request file and line links open that file (#34607)

Julius Marminge committed Nov 11, 2026 at 15:16 UTC 3a0bcba00a290be95621244819f031a619d84d7d
2 files changed +35 -2
packages/shared/src/pullRequestAnchor.test.ts
+19
@@ -133,3 +133,22 @@ it("finds a review with no text of its own through the earliest comment it poste
133 );
134 expect(resolvePullRequestReviewAnchor("issuecomment-9", [], threads)).toBe("issuecomment-9");
135 });
136 +
137 +it("reads GitLab merge request file and line anchors", () => {
138 + const path = "internal/commands/issuable/view/issuable_view_test.go";
139 + const digest = "0cd3702f060909d3161d1095b8347d4d07671427";
140 + expect(pullRequestDiffPathMatches(digest, path)).toBe(true);
141 + expect(parsePullRequestAnchor(`${gitlab}/diffs#${digest}`)).toEqual({
142 + kind: "diff",
143 + digest,
144 + range: null,
145 + });
146 + expect(parsePullRequestAnchor(`${gitlab}/diffs#${digest}_248_253`)).toEqual({
147 + kind: "diff",
148 + digest,
149 + range: { start: 253, side: "right", end: 253, endSide: "right" },
150 + });
151 + expect(parsePullRequestAnchor(`${gitlab}/diffs#${digest}_12_0`)).toMatchObject({
152 + range: { start: 12, side: "left" },
153 + });
154 +});
packages/shared/src/pullRequestAnchor.ts
+16 -2
@@ -1,4 +1,4 @@
1 -import { md5 } from "@noble/hashes/legacy";
1 +import { md5, sha1 } from "@noble/hashes/legacy";
2 import { sha256 } from "@noble/hashes/sha2";
3 import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils";
4
@@ -90,6 +90,19 @@ export function parsePullRequestAnchor(url: string | null | undefined): PullRequ
90 : null,
91 };
92 }
93 + // GitLab: SHA-1 of the path, then old and new line counters. A removed line still carries a
94 + // new counter, so the new side wins unless the file has none (a 0 for a deleted file).
95 + const gitlab = /^([a-f0-9]{40})(?:_(\d+)_(\d+))?$/i.exec(anchor);
96 + if (gitlab) {
97 + const digest = (gitlab[1] ?? "").toLowerCase();
98 + if (!gitlab[2]) return { kind: "diff", digest, range: null };
99 + const newLine = Number(gitlab[3]);
100 + const oldLine = Number(gitlab[2]);
101 + const side = newLine >= 1 ? "right" : "left";
102 + const line = side === "right" ? newLine : oldLine;
103 + if (!Number.isSafeInteger(line) || line < 1) return fallback;
104 + return { kind: "diff", digest, range: { start: line, side, end: line, endSide: side } };
105 + }
106 if (
107 /^(?:(?:issuecomment-|pullrequestreview-|discussion_r|r|commitcomment-|event-|note_|comment-)\d+|discussion-diff-\d+(?:[LR]\d+(?:-[LR]\d+)?)?)$/i.test(
108 anchor,
@@ -136,7 +149,8 @@ export function resolvePullRequestReviewAnchor(
149
150 export function pullRequestDiffPathMatches(digest: string, path: string): boolean {
151 const bytes = utf8ToBytes(path);
139 - return digest === bytesToHex(digest.length === 32 ? md5(bytes) : sha256(bytes));
152 + const hash = digest.length === 32 ? md5 : digest.length === 40 ? sha1 : sha256;
153 + return digest === bytesToHex(hash(bytes));
154 }
155
156 export function pullRequestLinkCommit(url: string | null | undefined): string | null {