Skip to content

Commit bd7da7f

Browse files
TonybynMp4claudejuliusmarminge
authored
fix(gitlab): unresolved overview threads count as review findings (#30397)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent d929e72 commit bd7da7f

5 files changed

Lines changed: 185 additions & 92 deletions

File tree

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.test.ts‎

Lines changed: 115 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,93 +1236,127 @@ layer("GitLabPullRequestCli.layer", (it) => {
12361236
}),
12371237
);
12381238

1239-
it.effect("reads a positioned discussion as a thread anchored to its line", () =>
1240-
Effect.gen(function* () {
1241-
mockedExecute.mockReturnValueOnce(
1242-
Effect.succeed(
1243-
output(
1244-
JSON.stringify([
1245-
{
1246-
id: "abc123",
1247-
notes: [
1248-
{
1249-
id: 1,
1250-
body: "rename this",
1251-
author: { username: "bilal", avatar_url: "https://avatars/b.png" },
1252-
created_at: "2026-07-01T00:00:00Z",
1253-
resolvable: true,
1254-
resolved: true,
1255-
position: {
1256-
position_type: "text",
1257-
new_path: "src/a.ts",
1258-
old_path: "src/a.ts",
1259-
new_line: 12,
1260-
old_line: null,
1239+
it.effect(
1240+
"reads a positioned discussion as a thread and an open overview discussion as a finding",
1241+
() =>
1242+
Effect.gen(function* () {
1243+
mockedExecute.mockReturnValueOnce(
1244+
Effect.succeed(
1245+
output(
1246+
JSON.stringify([
1247+
{
1248+
id: "abc123",
1249+
notes: [
1250+
{
1251+
id: 1,
1252+
body: "rename this",
1253+
author: { username: "bilal", avatar_url: "https://avatars/b.png" },
1254+
created_at: "2026-07-01T00:00:00Z",
1255+
resolvable: true,
1256+
resolved: true,
1257+
position: {
1258+
position_type: "text",
1259+
new_path: "src/a.ts",
1260+
old_path: "src/a.ts",
1261+
new_line: 12,
1262+
old_line: null,
1263+
},
12611264
},
1262-
},
1263-
{
1264-
id: 2,
1265-
body: "done",
1266-
author: { username: "julius" },
1267-
created_at: "2026-07-01T01:00:00Z",
1268-
},
1269-
],
1270-
},
1271-
{ id: "def456", notes: [{ id: 3, body: "ship it", created_at: "2026-07-01Z" }] },
1272-
{
1273-
id: "file789",
1274-
notes: [
1275-
{
1276-
id: 4,
1277-
body: "split this file",
1278-
created_at: "2026-07-01Z",
1279-
position: {
1280-
position_type: "file",
1281-
new_path: "src/b.ts",
1282-
old_path: "src/b.ts",
1283-
new_line: null,
1284-
old_line: null,
1265+
{
1266+
id: 2,
1267+
body: "done",
1268+
author: { username: "julius" },
1269+
created_at: "2026-07-01T01:00:00Z",
12851270
},
1286-
},
1287-
],
1288-
},
1289-
{
1290-
id: "img012",
1291-
notes: [
1292-
{
1293-
id: 5,
1294-
body: "logo is blurry",
1295-
created_at: "2026-07-01Z",
1296-
position: {
1297-
position_type: "image",
1298-
new_path: "logo.png",
1299-
old_path: "logo.png",
1300-
new_line: null,
1301-
old_line: null,
1271+
],
1272+
},
1273+
{ id: "def456", notes: [{ id: 3, body: "ship it", created_at: "2026-07-01Z" }] },
1274+
{
1275+
id: "ghi789",
1276+
notes: [
1277+
{
1278+
id: 4,
1279+
body: "mention the new flag in the README",
1280+
created_at: "2026-07-01T02:00:00Z",
1281+
resolvable: true,
1282+
resolved: false,
13021283
},
1303-
},
1304-
],
1305-
},
1306-
]),
1284+
{
1285+
id: 5,
1286+
body: "will do",
1287+
created_at: "2026-07-01T03:00:00Z",
1288+
resolvable: true,
1289+
resolved: false,
1290+
},
1291+
],
1292+
},
1293+
{
1294+
id: "jkl012",
1295+
notes: [
1296+
{
1297+
id: 6,
1298+
body: "already addressed",
1299+
created_at: "2026-07-01T04:00:00Z",
1300+
resolvable: true,
1301+
resolved: true,
1302+
},
1303+
],
1304+
},
1305+
{
1306+
id: "file789",
1307+
notes: [
1308+
{
1309+
id: 7,
1310+
body: "split this file",
1311+
created_at: "2026-07-01Z",
1312+
position: {
1313+
position_type: "file",
1314+
new_path: "src/b.ts",
1315+
old_path: "src/b.ts",
1316+
new_line: null,
1317+
old_line: null,
1318+
},
1319+
},
1320+
],
1321+
},
1322+
{
1323+
id: "img012",
1324+
notes: [
1325+
{
1326+
id: 8,
1327+
body: "logo is blurry",
1328+
created_at: "2026-07-01Z",
1329+
position: {
1330+
position_type: "image",
1331+
new_path: "logo.png",
1332+
old_path: "logo.png",
1333+
new_line: null,
1334+
old_line: null,
1335+
},
1336+
},
1337+
],
1338+
},
1339+
]),
1340+
),
13071341
),
1308-
),
1309-
);
1310-
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
1342+
);
1343+
const cli = yield* GitLabPullRequestCli.GitLabPullRequestCli;
13111344

1312-
const { threads } = yield* cli.listDiscussions({
1313-
cwd: "/w",
1314-
repository: "acme/web",
1315-
number: 7,
1316-
});
1345+
const { threads, overviewFindingIds } = yield* cli.listDiscussions({
1346+
cwd: "/w",
1347+
repository: "acme/web",
1348+
number: 7,
1349+
});
13171350

1318-
expect(threads.map(({ id, path, line, side }) => ({ id, path, line, side }))).toEqual([
1319-
{ id: "abc123", path: "src/a.ts", line: 12, side: "right" },
1320-
{ id: "file789", path: "src/b.ts", line: null, side: "right" },
1321-
{ id: "img012", path: "logo.png", line: null, side: "right" },
1322-
]);
1323-
expect(threads[0]).toMatchObject({ isResolved: true });
1324-
assert.strictEqual(threads[0]?.comments.length, 2);
1325-
}),
1351+
expect(overviewFindingIds).toEqual(["4"]);
1352+
expect(threads.map(({ id, path, line, side }) => ({ id, path, line, side }))).toEqual([
1353+
{ id: "abc123", path: "src/a.ts", line: 12, side: "right" },
1354+
{ id: "file789", path: "src/b.ts", line: null, side: "right" },
1355+
{ id: "img012", path: "logo.png", line: null, side: "right" },
1356+
]);
1357+
expect(threads[0]).toMatchObject({ isResolved: true });
1358+
assert.strictEqual(threads[0]?.comments.length, 2);
1359+
}),
13261360
);
13271361

13281362
it.effect("sends a review as its comments, then its summary, then the verdict", () =>

‎packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,11 @@ export class GitLabPullRequestCli extends Context.Service<
524524
readonly repository: string;
525525
readonly number: number;
526526
}) => Effect.Effect<
527-
{ readonly threads: ReadonlyArray<PullRequestReviewThread>; readonly truncated: boolean },
527+
{
528+
readonly threads: ReadonlyArray<PullRequestReviewThread>;
529+
readonly overviewFindingIds: ReadonlyArray<string>;
530+
readonly truncated: boolean;
531+
},
528532
GitLabPullRequestCliError
529533
>;
530534

@@ -1069,8 +1073,13 @@ export const make = Effect.gen(function* () {
10691073
readonly number: number;
10701074
readonly page: number;
10711075
readonly collected: ReadonlyArray<PullRequestReviewThread>;
1076+
readonly collectedFindingIds: ReadonlyArray<string>;
10721077
}): Effect.Effect<
1073-
{ readonly threads: ReadonlyArray<PullRequestReviewThread>; readonly truncated: boolean },
1078+
{
1079+
readonly threads: ReadonlyArray<PullRequestReviewThread>;
1080+
readonly overviewFindingIds: ReadonlyArray<string>;
1081+
readonly truncated: boolean;
1082+
},
10741083
GitLabPullRequestCliError
10751084
> =>
10761085
api({
@@ -1096,13 +1105,21 @@ export const make = Effect.gen(function* () {
10961105
);
10971106
}
10981107
const collected = [...input.collected, ...decoded.success.threads];
1108+
const collectedFindingIds = [
1109+
...input.collectedFindingIds,
1110+
...decoded.success.overviewFindingIds,
1111+
];
1112+
const done = (truncated: boolean) =>
1113+
Effect.succeed({
1114+
threads: collected,
1115+
overviewFindingIds: collectedFindingIds,
1116+
truncated,
1117+
});
10991118
// Plain notes count toward the page size even when no positioned threads survive decoding.
1100-
if (decoded.success.rawCount < MAX_PAGE_SIZE) {
1101-
return Effect.succeed({ threads: collected, truncated: false });
1102-
}
1119+
if (decoded.success.rawCount < MAX_PAGE_SIZE) return done(false);
11031120
return input.page >= CONVERSATION_PAGES
1104-
? Effect.succeed({ threads: collected, truncated: true })
1105-
: discussionsPage({ ...input, page: input.page + 1, collected });
1121+
? done(true)
1122+
: discussionsPage({ ...input, page: input.page + 1, collected, collectedFindingIds });
11061123
}),
11071124
);
11081125

@@ -2278,7 +2295,7 @@ export const make = Effect.gen(function* () {
22782295
}),
22792296

22802297
listDiscussions: Effect.fn("GitLabPullRequestCli.listDiscussions")(function (input) {
2281-
return discussionsPage({ ...input, page: 1, collected: [] });
2298+
return discussionsPage({ ...input, page: 1, collected: [], collectedFindingIds: [] });
22822299
}),
22832300

22842301
submitReview: Effect.fn("GitLabPullRequestCli.submitReview")(function* (input) {

‎packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts‎

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ describe("optional activity reads", () => {
532532
}),
533533
listNotes: () => Effect.succeed({ comments: [comment], truncated: false }),
534534
listCommits: () => Effect.succeed([commit]),
535-
listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),
535+
listDiscussions: () =>
536+
Effect.succeed({ threads: [], overviewFindingIds: [], truncated: false }),
536537
listReactions: () =>
537538
Effect.succeed({
538539
reactions: [],
@@ -586,6 +587,32 @@ describe("optional activity reads", () => {
586587
}),
587588
);
588589

590+
it.effect("turns the first note of an open overview discussion into a review finding", () =>
591+
Effect.gen(function* () {
592+
const finding = { ...comment, id: "10", body: "Mention the flag in the README" };
593+
const reply = { ...comment, id: "11", body: "Will do" };
594+
const provider = yield* make.pipe(
595+
Effect.provide(
596+
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
597+
...reads,
598+
listNotes: () =>
599+
Effect.succeed({ comments: [comment, finding, reply], truncated: false }),
600+
listDiscussions: () =>
601+
Effect.succeed({ threads: [], overviewFindingIds: ["10"], truncated: false }),
602+
}),
603+
),
604+
);
605+
606+
const { comments } = yield* provider.getChangeRequestActivity(reference);
607+
608+
expect(comments.map((item) => [item.id, item.kind])).toEqual([
609+
["42", "issue-comment"],
610+
["10", "review-comment"],
611+
["11", "issue-comment"],
612+
]);
613+
}),
614+
);
615+
589616
it.effect("dates edited comments in the conversation and in threads", () =>
590617
Effect.gen(function* () {
591618
const editedAt = "2026-07-02T00:00:00Z";
@@ -606,6 +633,7 @@ describe("optional activity reads", () => {
606633
comments: [comment],
607634
},
608635
],
636+
overviewFindingIds: [],
609637
truncated: false,
610638
}),
611639
listReactions: () =>
@@ -645,6 +673,7 @@ describe("optional activity reads", () => {
645673
comments: [comment],
646674
},
647675
],
676+
overviewFindingIds: [],
648677
truncated: false,
649678
}),
650679
}),
@@ -721,6 +750,7 @@ describe("optional activity reads", () => {
721750
],
722751
},
723752
],
753+
overviewFindingIds: [],
724754
truncated: false,
725755
}),
726756
listReactions: () =>

‎packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,11 @@ export const make = Effect.gen(function* () {
362362
[
363363
recoverRead(cli.listNotes(input), { comments: [], truncated: true }),
364364
recoverRead(cli.listCommits(input), []),
365-
recoverRead(cli.listDiscussions(input), { threads: [], truncated: true }),
365+
recoverRead(cli.listDiscussions(input), {
366+
threads: [],
367+
overviewFindingIds: [],
368+
truncated: true,
369+
}),
366370
recoverRead(cli.listReactions(input), {
367371
reactions: [] as ReadonlyArray<PullRequestReaction>,
368372
reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
@@ -381,6 +385,7 @@ export const make = Effect.gen(function* () {
381385
Effect.map(
382386
([notes, commits, discussions, awards, webUrl]): ProviderChangeRequestActivity => {
383387
const noteUrl = (id: string) => (webUrl === null ? null : `${webUrl}#note_${id}`);
388+
const findingIds = new Set(discussions.overviewFindingIds);
384389
const edited = (id: string) => {
385390
const editedAt = awards.editedAtByNoteId.get(id);
386391
return editedAt === undefined ? {} : { editedAt };
@@ -394,6 +399,7 @@ export const make = Effect.gen(function* () {
394399
reactions: awards.reactions,
395400
comments: notes.comments.map((comment) => ({
396401
...comment,
402+
...(findingIds.has(comment.id) ? { kind: "review-comment" as const } : {}),
397403
...edited(comment.id),
398404
author: withBotFlag(comment.author),
399405
url: noteUrl(comment.id),

0 commit comments

Comments
 (0)