Skip to content
TypeScript

fix(gitlab): file and image comments appear as review threads (#30425)

Antony25b53299b75d
diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
index 597d43b8f53..231cb8db3cb 100644
--- a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
+++ b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts
@@ -1022,6 +1022,40 @@ layer("GitLabPullRequestCli.layer", (it) => {
],
},
{ id: "def456", notes: [{ id: 3, body: "ship it", created_at: "2026-07-01Z" }] },
+ {
+ id: "file789",
+ notes: [
+ {
+ id: 4,
+ body: "split this file",
+ created_at: "2026-07-01Z",
+ position: {
+ position_type: "file",
+ new_path: "src/b.ts",
+ old_path: "src/b.ts",
+ new_line: null,
+ old_line: null,
+ },
+ },
+ ],
+ },
+ {
+ id: "img012",
+ notes: [
+ {
+ id: 5,
+ body: "logo is blurry",
+ created_at: "2026-07-01Z",
+ position: {
+ position_type: "image",
+ new_path: "logo.png",
+ old_path: "logo.png",
+ new_line: null,
+ old_line: null,
+ },
+ },
+ ],
+ },
]),
),
),
@@ -1034,14 +1068,12 @@ layer("GitLabPullRequestCli.layer", (it) => {
number: 7,
});
- assert.strictEqual(threads.length, 1);
- expect(threads[0]).toMatchObject({
- id: "abc123",
- path: "src/a.ts",
- line: 12,
- side: "right",
- isResolved: true,
- });
+ expect(threads.map(({ id, path, line, side }) => ({ id, path, line, side }))).toEqual([
+ { id: "abc123", path: "src/a.ts", line: 12, side: "right" },
+ { id: "file789", path: "src/b.ts", line: null, side: "right" },
+ { id: "img012", path: "logo.png", line: null, side: "right" },
+ ]);
+ expect(threads[0]).toMatchObject({ isResolved: true });
assert.strictEqual(threads[0]?.comments.length, 2);
}),
);
diff --git a/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts b/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
index a4acbe3a18b..8ce3616536e 100644
--- a/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+++ b/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
@@ -547,10 +547,21 @@ export function decodeDiscussionsJson(
const notes = (discussion.value.notes ?? []).filter((note) => note.system !== true);
const root = notes[0];
const position = root?.position;
- if (root === undefined || !position || position.position_type !== "text") continue;
- const side = position.new_line === null || position.new_line === undefined ? "left" : "right";
- const path = trimmed(side === "left" ? position.old_path : position.new_path);
- const line = side === "left" ? position.old_line : position.new_line;
+ if (root === undefined || !position) continue;
+ let side: "left" | "right";
+ let path: string | null;
+ let line: number | null | undefined;
+ if (position.position_type === "text") {
+ side = position.new_line === null || position.new_line === undefined ? "left" : "right";
+ path = trimmed(side === "left" ? position.old_path : position.new_path);
+ line = side === "left" ? position.old_line : position.new_line;
+ } else if (position.position_type === "file" || position.position_type === "image") {
+ side = "right";
+ path = trimmed(position.new_path) ?? trimmed(position.old_path);
+ line = null;
+ } else {
+ continue;
+ }
if (path === null) continue;
threads.push({
id: discussion.value.id,