Skip to content

Commit 05bd5a1

Browse files
TonybynMp4claudejuliusmarminge
authored
fix(gitlab): comments link to their note on GitLab (#30411)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent b871551 commit 05bd5a1

2 files changed

Lines changed: 99 additions & 29 deletions

File tree

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

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,34 @@ describe("optional activity reads", () => {
502502
messageHeadline: "Keep this commit",
503503
committedDate: "2026-07-01T00:00:00Z",
504504
};
505+
const webUrl = "https://git.acme.dev/acme/web/-/merge_requests/7";
505506
const reads = {
507+
getMergeRequestDetail: () =>
508+
Effect.succeed({
509+
number: 7,
510+
title: "Merge request 7",
511+
url: webUrl,
512+
author: null,
513+
headBranch: "feat/page",
514+
baseBranch: "main",
515+
state: "open" as const,
516+
isDraft: false,
517+
mergeability: "mergeable" as const,
518+
additions: 0,
519+
deletions: 0,
520+
createdAt: "2026-07-01T00:00:00Z",
521+
updatedAt: "2026-07-02T00:00:00Z",
522+
reviewRequestLogins: [],
523+
labels: [],
524+
body: "",
525+
changedFiles: 1,
526+
mergedAt: null,
527+
closedAt: null,
528+
reviewers: [],
529+
checks: [],
530+
viewerCanMerge: true,
531+
reviewerIds: [],
532+
}),
506533
listNotes: () => Effect.succeed({ comments: [comment], truncated: false }),
507534
listCommits: () => Effect.succeed([commit]),
508535
listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),
@@ -599,7 +626,39 @@ describe("optional activity reads", () => {
599626
}),
600627
);
601628

602-
it.effect("keeps comments and commits when optional discussions and reactions fail", () =>
629+
it.effect("links comments and thread comments to their note on the merge request page", () =>
630+
Effect.gen(function* () {
631+
const provider = yield* make.pipe(
632+
Effect.provide(
633+
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
634+
...reads,
635+
listDiscussions: () =>
636+
Effect.succeed({
637+
threads: [
638+
{
639+
id: "d1",
640+
path: "src/a.ts",
641+
line: 1,
642+
side: "right" as const,
643+
isResolved: false,
644+
isOutdated: false,
645+
comments: [comment],
646+
},
647+
],
648+
truncated: false,
649+
}),
650+
}),
651+
),
652+
);
653+
654+
const activity = yield* provider.getChangeRequestActivity(reference);
655+
656+
expect(activity.comments[0]?.url).toBe(`${webUrl}#note_42`);
657+
expect(activity.reviewThreads[0]?.comments[0]?.url).toBe(`${webUrl}#note_42`);
658+
}),
659+
);
660+
661+
it.effect("keeps comments and commits when optional discussions, reactions and links fail", () =>
603662
Effect.gen(function* () {
604663
const provider = yield* make.pipe(
605664
Effect.provide(
@@ -615,6 +674,7 @@ describe("optional activity reads", () => {
615674
}),
616675
),
617676
listReactions: () => Effect.fail(new GitLabCli.GitLabCliCommandError(context)),
677+
getMergeRequestDetail: () => Effect.fail(new GitLabCli.GitLabCliCommandError(context)),
618678
}),
619679
),
620680
);

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

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -341,42 +341,52 @@ export const make = Effect.gen(function* () {
341341
editedAtByNoteId: new Map<string, string>(),
342342
botLogins: new Set<string>(),
343343
}),
344+
// Usually cached by the detail read beside this one; web_url holds the real web origin.
345+
recoverRead(
346+
mergeRequestDetail(input).pipe(Effect.map((mergeRequest) => mergeRequest.url)),
347+
null,
348+
),
344349
],
345-
{ concurrency: 4 },
350+
{ concurrency: 5 },
346351
).pipe(
347352
Effect.mapError(fail("getChangeRequestActivity")),
348-
Effect.map(([notes, commits, discussions, awards]): ProviderChangeRequestActivity => {
349-
const edited = (id: string) => {
350-
const editedAt = awards.editedAtByNoteId.get(id);
351-
return editedAt === undefined ? {} : { editedAt };
352-
};
353-
const botLogins = new Set([...awards.botLogins].map((login) => login.toLowerCase()));
354-
const withBotFlag = (author: PullRequestActor | null) =>
355-
author !== null && botLogins.has(author.login.toLowerCase())
356-
? { ...author, isBot: true }
357-
: author;
358-
return {
359-
reactions: awards.reactions,
360-
comments: notes.comments.map((comment) => ({
361-
...comment,
362-
...edited(comment.id),
363-
author: withBotFlag(comment.author),
364-
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
365-
})),
366-
commentCount: notes.comments.length,
367-
commentsTruncated: notes.truncated || discussions.truncated,
368-
reviewThreads: discussions.threads.map((thread) => ({
369-
...thread,
370-
comments: thread.comments.map((comment) => ({
353+
Effect.map(
354+
([notes, commits, discussions, awards, webUrl]): ProviderChangeRequestActivity => {
355+
const noteUrl = (id: string) => (webUrl === null ? null : `${webUrl}#note_${id}`);
356+
const edited = (id: string) => {
357+
const editedAt = awards.editedAtByNoteId.get(id);
358+
return editedAt === undefined ? {} : { editedAt };
359+
};
360+
const botLogins = new Set([...awards.botLogins].map((login) => login.toLowerCase()));
361+
const withBotFlag = (author: PullRequestActor | null) =>
362+
author !== null && botLogins.has(author.login.toLowerCase())
363+
? { ...author, isBot: true }
364+
: author;
365+
return {
366+
reactions: awards.reactions,
367+
comments: notes.comments.map((comment) => ({
371368
...comment,
372369
...edited(comment.id),
373370
author: withBotFlag(comment.author),
371+
url: noteUrl(comment.id),
374372
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
375373
})),
376-
})),
377-
commits,
378-
};
379-
}),
374+
commentCount: notes.comments.length,
375+
commentsTruncated: notes.truncated || discussions.truncated,
376+
reviewThreads: discussions.threads.map((thread) => ({
377+
...thread,
378+
comments: thread.comments.map((comment) => ({
379+
...comment,
380+
...edited(comment.id),
381+
author: withBotFlag(comment.author),
382+
url: noteUrl(comment.id),
383+
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
384+
})),
385+
})),
386+
commits,
387+
};
388+
},
389+
),
380390
),
381391

382392
// Straight from the host, never the shared read: this is what a write is refused or let

0 commit comments

Comments
 (0)