Skip to content

Commit b8fa652

Browse files
TonybynMp4claude
andcommitted
fix(gitlab): edited comments wake PR watchers
GitLab comments never carried editedAt, so a bot that rewrites its summary comment in place never woke watch_pull_request. The reactions GraphQL query, which already walks every note, now also reads lastEditedAt, lastEditedBy and resolved. Resolving a thread moves lastEditedAt on all its notes, so the edit time is trusted only when lastEditedBy is set and the note is not resolved. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent aee76a8 commit b8fa652

5 files changed

Lines changed: 135 additions & 16 deletions

File tree

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ export class GitLabPullRequestCli extends Context.Service<
461461
{
462462
readonly reactions: ReadonlyArray<PullRequestReaction>;
463463
readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
464+
readonly editedAtByNoteId: ReadonlyMap<string, string>;
464465
},
465466
GitLabPullRequestCliError
466467
>;
@@ -1086,11 +1087,13 @@ export const make = Effect.gen(function* () {
10861087
readonly collected: {
10871088
readonly reactions: ReadonlyArray<PullRequestReaction>;
10881089
readonly reactionsByNoteId: Map<string, ReadonlyArray<PullRequestReaction>>;
1090+
readonly editedAtByNoteId: Map<string, string>;
10891091
} | null;
10901092
}): Effect.Effect<
10911093
{
10921094
readonly reactions: ReadonlyArray<PullRequestReaction>;
10931095
readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
1096+
readonly editedAtByNoteId: ReadonlyMap<string, string>;
10941097
},
10951098
GitLabPullRequestCliError
10961099
> =>
@@ -1123,9 +1126,12 @@ export const make = Effect.gen(function* () {
11231126
const collected = input.collected ?? {
11241127
reactions: decoded.success.reactions,
11251128
reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
1129+
editedAtByNoteId: new Map<string, string>(),
11261130
};
11271131
for (const [id, reactions] of decoded.success.reactionsByNoteId)
11281132
collected.reactionsByNoteId.set(id, reactions);
1133+
for (const [id, editedAt] of decoded.success.editedAtByNoteId)
1134+
collected.editedAtByNoteId.set(id, editedAt);
11291135
return decoded.success.nextCursor === null || input.page >= CONVERSATION_PAGES
11301136
? Effect.succeed(collected)
11311137
: awardsPage({

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ describe("optional activity reads", () => {
484484
listNotes: () => Effect.succeed({ comments: [comment], truncated: false }),
485485
listCommits: () => Effect.succeed([commit]),
486486
listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),
487-
listReactions: () => Effect.succeed({ reactions: [], reactionsByNoteId: new Map() }),
487+
listReactions: () =>
488+
Effect.succeed({ reactions: [], reactionsByNoteId: new Map(), editedAtByNoteId: new Map() }),
488489
};
489490
const context = {
490491
operation: "execute" as const,
@@ -531,6 +532,45 @@ describe("optional activity reads", () => {
531532
}),
532533
);
533534

535+
it.effect("dates edited comments in the conversation and in threads", () =>
536+
Effect.gen(function* () {
537+
const editedAt = "2026-07-02T00:00:00Z";
538+
const provider = yield* make.pipe(
539+
Effect.provide(
540+
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
541+
...reads,
542+
listDiscussions: () =>
543+
Effect.succeed({
544+
threads: [
545+
{
546+
id: "d1",
547+
path: "src/a.ts",
548+
line: 1,
549+
side: "right" as const,
550+
isResolved: false,
551+
isOutdated: false,
552+
comments: [comment],
553+
},
554+
],
555+
truncated: false,
556+
}),
557+
listReactions: () =>
558+
Effect.succeed({
559+
reactions: [],
560+
reactionsByNoteId: new Map(),
561+
editedAtByNoteId: new Map([[comment.id, editedAt]]),
562+
}),
563+
}),
564+
),
565+
);
566+
567+
const activity = yield* provider.getChangeRequestActivity(reference);
568+
569+
expect(activity.comments[0]?.editedAt).toBe(editedAt);
570+
expect(activity.reviewThreads[0]?.comments[0]?.editedAt).toBe(editedAt);
571+
}),
572+
);
573+
534574
it.effect("keeps comments and commits when optional discussions and reactions fail", () =>
535575
Effect.gen(function* () {
536576
const provider = yield* make.pipe(

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -328,28 +328,37 @@ export const make = Effect.gen(function* () {
328328
recoverRead(cli.listReactions(input), {
329329
reactions: [] as ReadonlyArray<PullRequestReaction>,
330330
reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
331+
editedAtByNoteId: new Map<string, string>(),
331332
}),
332333
],
333334
{ concurrency: 4 },
334335
).pipe(
335336
Effect.mapError(fail("getChangeRequestActivity")),
336-
Effect.map(([notes, commits, discussions, awards]): ProviderChangeRequestActivity => ({
337-
reactions: awards.reactions,
338-
comments: notes.comments.map((comment) => ({
339-
...comment,
340-
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
341-
})),
342-
commentCount: notes.comments.length,
343-
commentsTruncated: notes.truncated || discussions.truncated,
344-
reviewThreads: discussions.threads.map((thread) => ({
345-
...thread,
346-
comments: thread.comments.map((comment) => ({
337+
Effect.map(([notes, commits, discussions, awards]): ProviderChangeRequestActivity => {
338+
const edited = (id: string) => {
339+
const editedAt = awards.editedAtByNoteId.get(id);
340+
return editedAt === undefined ? {} : { editedAt };
341+
};
342+
return {
343+
reactions: awards.reactions,
344+
comments: notes.comments.map((comment) => ({
347345
...comment,
346+
...edited(comment.id),
348347
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
349348
})),
350-
})),
351-
commits,
352-
})),
349+
commentCount: notes.comments.length,
350+
commentsTruncated: notes.truncated || discussions.truncated,
351+
reviewThreads: discussions.threads.map((thread) => ({
352+
...thread,
353+
comments: thread.comments.map((comment) => ({
354+
...comment,
355+
...edited(comment.id),
356+
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
357+
})),
358+
})),
359+
commits,
360+
};
361+
}),
353362
),
354363

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

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,48 @@ describe("decodeAwardEmojiJson", () => {
539539
expect(result.nextCursor).toBeNull();
540540
});
541541

542+
it("dates a note's edit only when someone edited its text, not when its thread was resolved", () => {
543+
const result = expectSuccess(
544+
decodeAwardEmojiJson(
545+
JSON.stringify({
546+
data: {
547+
currentUser: { username: "bilal" },
548+
project: {
549+
mergeRequest: {
550+
awardEmoji: { nodes: [] },
551+
notes: {
552+
pageInfo: { hasNextPage: false, endCursor: null },
553+
nodes: [
554+
{
555+
id: "gid://gitlab/Note/1",
556+
lastEditedAt: "2026-07-02T00:00:00Z",
557+
lastEditedBy: { username: "julius" },
558+
resolved: false,
559+
},
560+
{
561+
id: "gid://gitlab/Note/2",
562+
lastEditedAt: "2026-07-01T00:00:00Z",
563+
lastEditedBy: null,
564+
resolved: false,
565+
},
566+
{
567+
id: "gid://gitlab/DiscussionNote/3",
568+
lastEditedAt: "2026-07-03T00:00:00Z",
569+
lastEditedBy: { username: "julius" },
570+
resolved: true,
571+
},
572+
],
573+
},
574+
},
575+
},
576+
},
577+
}),
578+
),
579+
);
580+
581+
expect([...result.editedAtByNoteId]).toEqual([["1", "2026-07-02T00:00:00Z"]]);
582+
});
583+
542584
it("matches the viewer's username case-insensitively, since GitLab is not consistent about case", () => {
543585
const result = expectSuccess(
544586
decodeAwardEmojiJson(

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ export const AWARD_EMOJI_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!, $
767767
awardEmoji { nodes { name user { username } } }
768768
notes(first: 100, after: $cursor) {
769769
pageInfo { hasNextPage endCursor }
770-
nodes { id awardEmoji { nodes { name user { username } } } }
770+
nodes { id lastEditedAt lastEditedBy { username } resolved awardEmoji { nodes { name user { username } } } }
771771
}
772772
}
773773
}
@@ -819,6 +819,15 @@ const RawAwardEmojiPageSchema = Schema.Struct({
819819
Schema.NullOr(
820820
Schema.Struct({
821821
id: Schema.optional(Schema.NullOr(Schema.String)),
822+
lastEditedAt: Schema.optional(Schema.NullOr(Schema.String)),
823+
lastEditedBy: Schema.optional(
824+
Schema.NullOr(
825+
Schema.Struct({
826+
username: Schema.optional(Schema.NullOr(Schema.String)),
827+
}),
828+
),
829+
),
830+
resolved: Schema.optional(Schema.NullOr(Schema.Boolean)),
822831
awardEmoji: RawAwardEmojiNodesSchema,
823832
}),
824833
),
@@ -873,6 +882,7 @@ function noteIdOf(gid: string | null | undefined): string | null {
873882
export interface GitLabAwardEmojiPage {
874883
readonly reactions: ReadonlyArray<PullRequestReaction>;
875884
readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
885+
readonly editedAtByNoteId: ReadonlyMap<string, string>;
876886
readonly nextCursor: string | null;
877887
}
878888

@@ -887,16 +897,28 @@ export function decodeAwardEmojiJson(
887897
const viewer = trimmed(data.currentUser?.username);
888898
const mergeRequest = data.project?.mergeRequest;
889899
const reactionsByNoteId = new Map<string, ReadonlyArray<PullRequestReaction>>();
900+
const editedAtByNoteId = new Map<string, string>();
890901
for (const node of mergeRequest?.notes?.nodes ?? []) {
891902
const id = noteIdOf(node?.id);
892903
if (id === null) continue;
893904
const reactions = toReactions(node?.awardEmoji, viewer);
894905
if (reactions.length > 0) reactionsByNoteId.set(id, reactions);
906+
// Resolving a thread moves lastEditedAt on every note in it; only lastEditedBy marks a
907+
// text edit, and a resolved note's stamp may be the resolve rather than that edit.
908+
const editedAt = trimmed(node?.lastEditedAt);
909+
if (
910+
editedAt !== null &&
911+
trimmed(node?.lastEditedBy?.username) !== null &&
912+
node?.resolved !== true
913+
) {
914+
editedAtByNoteId.set(id, editedAt);
915+
}
895916
}
896917
const pageInfo = mergeRequest?.notes?.pageInfo;
897918
return Result.succeed({
898919
reactions: toReactions(mergeRequest?.awardEmoji, viewer),
899920
reactionsByNoteId,
921+
editedAtByNoteId,
900922
nextCursor: pageInfo?.hasNextPage === true ? (trimmed(pageInfo.endCursor) ?? null) : null,
901923
});
902924
}

0 commit comments

Comments
 (0)