TypeScript
fix(gitlab): edited comments wake PR watchers (#30403)
Antonye136e8e3d4cb
diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.tsindex 7546e3ad532..fc0a8577851 100644--- a/packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts+++ b/packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts@@ -504,6 +504,7 @@ export class GitLabPullRequestCli extends Context.Service<{readonly reactions: ReadonlyArray<PullRequestReaction>;readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;+ readonly editedAtByNoteId: ReadonlyMap<string, string>;readonly botLogins: ReadonlySet<string>;},GitLabPullRequestCliError@@ -1130,12 +1131,14 @@ export const make = Effect.gen(function* () {readonly collected: {readonly reactions: ReadonlyArray<PullRequestReaction>;readonly reactionsByNoteId: Map<string, ReadonlyArray<PullRequestReaction>>;+ readonly editedAtByNoteId: Map<string, string>;readonly botLogins: Set<string>;} | null;}): Effect.Effect<{readonly reactions: ReadonlyArray<PullRequestReaction>;readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;+ readonly editedAtByNoteId: ReadonlyMap<string, string>;readonly botLogins: ReadonlySet<string>;},GitLabPullRequestCliError@@ -1169,10 +1172,13 @@ export const make = Effect.gen(function* () {const collected = input.collected ?? {reactions: decoded.success.reactions,reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),+ editedAtByNoteId: new Map<string, string>(),botLogins: new Set<string>(),};for (const [id, reactions] of decoded.success.reactionsByNoteId)collected.reactionsByNoteId.set(id, reactions);+ for (const [id, editedAt] of decoded.success.editedAtByNoteId)+ collected.editedAtByNoteId.set(id, editedAt);for (const login of decoded.success.botLogins) collected.botLogins.add(login);return decoded.success.nextCursor === null || input.page >= CONVERSATION_PAGES? Effect.succeed(collected)diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.tsindex d36565839a1..26dde73a9fe 100644--- a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts+++ b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts@@ -500,7 +500,12 @@ describe("optional activity reads", () => {listCommits: () => Effect.succeed([commit]),listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),listReactions: () =>- Effect.succeed({ reactions: [], reactionsByNoteId: new Map(), botLogins: new Set<string>() }),+ Effect.succeed({+ reactions: [],+ reactionsByNoteId: new Map(),+ editedAtByNoteId: new Map(),+ botLogins: new Set<string>(),+ }),};const context = {operation: "execute" as const,@@ -547,6 +552,46 @@ describe("optional activity reads", () => {}),);+ it.effect("dates edited comments in the conversation and in threads", () =>+ Effect.gen(function* () {+ const editedAt = "2026-07-02T00:00:00Z";+ 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,+ }),+ listReactions: () =>+ Effect.succeed({+ reactions: [],+ reactionsByNoteId: new Map(),+ editedAtByNoteId: new Map([[comment.id, editedAt]]),+ botLogins: new Set<string>(),+ }),+ }),+ ),+ );++ const activity = yield* provider.getChangeRequestActivity(reference);++ expect(activity.comments[0]?.editedAt).toBe(editedAt);+ expect(activity.reviewThreads[0]?.comments[0]?.editedAt).toBe(editedAt);+ }),+ );+it.effect("keeps comments and commits when optional discussions and reactions fail", () =>Effect.gen(function* () {const provider = yield* make.pipe(@@ -615,6 +660,7 @@ describe("optional activity reads", () => {Effect.succeed({reactions: [],reactionsByNoteId: new Map(),+ editedAtByNoteId: new Map(),botLogins: new Set([bot.login.toUpperCase()]),}),}),diff --git a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.tsindex 6a7212bd45c..f852b96f351 100644--- a/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts+++ b/packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts@@ -334,6 +334,7 @@ export const make = Effect.gen(function* () {recoverRead(cli.listReactions(input), {reactions: [] as ReadonlyArray<PullRequestReaction>,reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),+ editedAtByNoteId: new Map<string, string>(),botLogins: new Set<string>(),}),],@@ -341,6 +342,10 @@ export const make = Effect.gen(function* () {).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())@@ -350,6 +355,7 @@ export const make = Effect.gen(function* () {reactions: awards.reactions,comments: notes.comments.map((comment) => ({...comment,+ ...edited(comment.id),author: withBotFlag(comment.author),reactions: awards.reactionsByNoteId.get(comment.id) ?? [],})),@@ -359,6 +365,7 @@ export const make = Effect.gen(function* () {...thread,comments: thread.comments.map((comment) => ({...comment,+ ...edited(comment.id),author: withBotFlag(comment.author),reactions: awards.reactionsByNoteId.get(comment.id) ?? [],})),diff --git a/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts b/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.tsindex 7bec611ce07..2b3ff84330c 100644--- a/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts+++ b/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts@@ -544,6 +544,48 @@ describe("decodeAwardEmojiJson", () => {expect(result.nextCursor).toBeNull();});+ it("dates a note's edit only when someone edited its text, not when its thread was resolved", () => {+ const result = expectSuccess(+ decodeAwardEmojiJson(+ JSON.stringify({+ data: {+ currentUser: { username: "bilal" },+ project: {+ mergeRequest: {+ awardEmoji: { nodes: [] },+ notes: {+ pageInfo: { hasNextPage: false, endCursor: null },+ nodes: [+ {+ id: "gid://gitlab/Note/1",+ lastEditedAt: "2026-07-02T00:00:00Z",+ lastEditedBy: { username: "julius" },+ resolved: false,+ },+ {+ id: "gid://gitlab/Note/2",+ lastEditedAt: "2026-07-01T00:00:00Z",+ lastEditedBy: null,+ resolved: false,+ },+ {+ id: "gid://gitlab/DiscussionNote/3",+ lastEditedAt: "2026-07-03T00:00:00Z",+ lastEditedBy: { username: "julius" },+ resolved: true,+ },+ ],+ },+ },+ },+ },+ }),+ ),+ );++ expect([...result.editedAtByNoteId]).toEqual([["1", "2026-07-02T00:00:00Z"]]);+ });+it("matches the viewer's username case-insensitively, since GitLab is not consistent about case", () => {const result = expectSuccess(decodeAwardEmojiJson(diff --git a/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts b/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.tsindex b514b018e84..1b6c1239449 100644--- a/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts+++ b/packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts@@ -801,7 +801,7 @@ export const AWARD_EMOJI_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!, $awardEmoji { nodes { name user { username } } }notes(first: 100, after: $cursor) {pageInfo { hasNextPage endCursor }- nodes { id author { username bot } awardEmoji { nodes { name user { username } } } }+ nodes { id author { username bot } lastEditedAt lastEditedBy { username } resolved awardEmoji { nodes { name user { username } } } }}}}@@ -853,6 +853,15 @@ const RawAwardEmojiPageSchema = Schema.Struct({Schema.NullOr(Schema.Struct({id: Schema.optional(Schema.NullOr(Schema.String)),+ lastEditedAt: Schema.optional(Schema.NullOr(Schema.String)),+ lastEditedBy: Schema.optional(+ Schema.NullOr(+ Schema.Struct({+ username: Schema.optional(Schema.NullOr(Schema.String)),+ }),+ ),+ ),+ resolved: Schema.optional(Schema.NullOr(Schema.Boolean)),// REST note authors carry no bot flag; GraphQL's does.author: Schema.optional(Schema.NullOr(@@ -916,6 +925,7 @@ function noteIdOf(gid: string | null | undefined): string | null {export interface GitLabAwardEmojiPage {readonly reactions: ReadonlyArray<PullRequestReaction>;readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;+ readonly editedAtByNoteId: ReadonlyMap<string, string>;readonly botLogins: ReadonlySet<string>;readonly nextCursor: string | null;}@@ -931,6 +941,7 @@ export function decodeAwardEmojiJson(const viewer = trimmed(data.currentUser?.username);const mergeRequest = data.project?.mergeRequest;const reactionsByNoteId = new Map<string, ReadonlyArray<PullRequestReaction>>();+ const editedAtByNoteId = new Map<string, string>();const botLogins = new Set<string>();for (const node of mergeRequest?.notes?.nodes ?? []) {const author = trimmed(node?.author?.username);@@ -939,11 +950,22 @@ export function decodeAwardEmojiJson(if (id === null) continue;const reactions = toReactions(node?.awardEmoji, viewer);if (reactions.length > 0) reactionsByNoteId.set(id, reactions);+ // Resolving a thread moves lastEditedAt on every note in it; only lastEditedBy marks a+ // text edit, and a resolved note's stamp may be the resolve rather than that edit.+ const editedAt = trimmed(node?.lastEditedAt);+ if (+ editedAt !== null &&+ trimmed(node?.lastEditedBy?.username) !== null &&+ node?.resolved !== true+ ) {+ editedAtByNoteId.set(id, editedAt);+ }}const pageInfo = mergeRequest?.notes?.pageInfo;return Result.succeed({reactions: toReactions(mergeRequest?.awardEmoji, viewer),reactionsByNoteId,+ editedAtByNoteId,botLogins,nextCursor: pageInfo?.hasNextPage === true ? (trimmed(pageInfo.endCursor) ?? null) : null,});