TypeScript
fix(gitlab): comments link to their note on GitLab (#30411)
Antony05bd5a1ca383
diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.tsindex e3b80e7c3b6..700b8a9c0aa 100644--- a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts+++ b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts@@ -502,7 +502,34 @@ describe("optional activity reads", () => {messageHeadline: "Keep this commit",committedDate: "2026-07-01T00:00:00Z",};+ const webUrl = "https://git.acme.dev/acme/web/-/merge_requests/7";const reads = {+ getMergeRequestDetail: () =>+ Effect.succeed({+ number: 7,+ title: "Merge request 7",+ url: webUrl,+ author: null,+ headBranch: "feat/page",+ baseBranch: "main",+ state: "open" as const,+ isDraft: false,+ mergeability: "mergeable" as const,+ additions: 0,+ deletions: 0,+ createdAt: "2026-07-01T00:00:00Z",+ updatedAt: "2026-07-02T00:00:00Z",+ reviewRequestLogins: [],+ labels: [],+ body: "",+ changedFiles: 1,+ mergedAt: null,+ closedAt: null,+ reviewers: [],+ checks: [],+ viewerCanMerge: true,+ reviewerIds: [],+ }),listNotes: () => Effect.succeed({ comments: [comment], truncated: false }),listCommits: () => Effect.succeed([commit]),listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),@@ -599,7 +626,39 @@ describe("optional activity reads", () => {}),);- it.effect("keeps comments and commits when optional discussions and reactions fail", () =>+ it.effect("links comments and thread comments to their note on the merge request page", () =>+ Effect.gen(function* () {+ const provider = yield* make.pipe(+ Effect.provide(+ Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({+ ...reads,+ listDiscussions: () =>+ Effect.succeed({+ threads: [+ {+ id: "d1",+ path: "src/a.ts",+ line: 1,+ side: "right" as const,+ isResolved: false,+ isOutdated: false,+ comments: [comment],+ },+ ],+ truncated: false,+ }),+ }),+ ),+ );++ const activity = yield* provider.getChangeRequestActivity(reference);++ expect(activity.comments[0]?.url).toBe(`${webUrl}#note_42`);+ expect(activity.reviewThreads[0]?.comments[0]?.url).toBe(`${webUrl}#note_42`);+ }),+ );++ it.effect("keeps comments and commits when optional discussions, reactions and links fail", () =>Effect.gen(function* () {const provider = yield* make.pipe(Effect.provide(@@ -615,6 +674,7 @@ describe("optional activity reads", () => {}),),listReactions: () => Effect.fail(new GitLabCli.GitLabCliCommandError(context)),+ getMergeRequestDetail: () => Effect.fail(new GitLabCli.GitLabCliCommandError(context)),}),),);diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.tsindex 8368747a261..9d2e4a1fc33 100644--- a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts+++ b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts@@ -341,42 +341,52 @@ export const make = Effect.gen(function* () {editedAtByNoteId: new Map<string, string>(),botLogins: new Set<string>(),}),+ // Usually cached by the detail read beside this one; web_url holds the real web origin.+ recoverRead(+ mergeRequestDetail(input).pipe(Effect.map((mergeRequest) => mergeRequest.url)),+ null,+ ),],- { concurrency: 4 },+ { concurrency: 5 },).pipe(Effect.mapError(fail("getChangeRequestActivity")),- Effect.map(([notes, commits, discussions, awards]): ProviderChangeRequestActivity => {- const edited = (id: string) => {- const editedAt = awards.editedAtByNoteId.get(id);- return editedAt === undefined ? {} : { editedAt };- };- const botLogins = new Set([...awards.botLogins].map((login) => login.toLowerCase()));- const withBotFlag = (author: PullRequestActor | null) =>- author !== null && botLogins.has(author.login.toLowerCase())- ? { ...author, isBot: true }- : author;- return {- reactions: awards.reactions,- comments: notes.comments.map((comment) => ({- ...comment,- ...edited(comment.id),- author: withBotFlag(comment.author),- reactions: awards.reactionsByNoteId.get(comment.id) ?? [],- })),- commentCount: notes.comments.length,- commentsTruncated: notes.truncated || discussions.truncated,- reviewThreads: discussions.threads.map((thread) => ({- ...thread,- comments: thread.comments.map((comment) => ({+ Effect.map(+ ([notes, commits, discussions, awards, webUrl]): ProviderChangeRequestActivity => {+ const noteUrl = (id: string) => (webUrl === null ? null : `${webUrl}#note_${id}`);+ const edited = (id: string) => {+ const editedAt = awards.editedAtByNoteId.get(id);+ return editedAt === undefined ? {} : { editedAt };+ };+ const botLogins = new Set([...awards.botLogins].map((login) => login.toLowerCase()));+ const withBotFlag = (author: PullRequestActor | null) =>+ author !== null && botLogins.has(author.login.toLowerCase())+ ? { ...author, isBot: true }+ : author;+ return {+ reactions: awards.reactions,+ comments: notes.comments.map((comment) => ({...comment,...edited(comment.id),author: withBotFlag(comment.author),+ url: noteUrl(comment.id),reactions: awards.reactionsByNoteId.get(comment.id) ?? [],})),- })),- commits,- };- }),+ commentCount: notes.comments.length,+ commentsTruncated: notes.truncated || discussions.truncated,+ reviewThreads: discussions.threads.map((thread) => ({+ ...thread,+ comments: thread.comments.map((comment) => ({+ ...comment,+ ...edited(comment.id),+ author: withBotFlag(comment.author),+ url: noteUrl(comment.id),+ reactions: awards.reactionsByNoteId.get(comment.id) ?? [],+ })),+ })),+ commits,+ };+ },+ ),),// Straight from the host, never the shared read: this is what a write is refused or let