Skip to content

Commit e136e8e

Browse files
TonybynMp4claudejuliusmarminge
authored
fix(gitlab): edited comments wake PR watchers (pingdotgg#30403)
Co-authored-by: Claude Opus 5.5 <[email protected]> Co-authored-by: Julius Marminge <[email protected]>
1 parent a21f89d commit e136e8e

5 files changed

Lines changed: 125 additions & 2 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
@@ -504,6 +504,7 @@ export class GitLabPullRequestCli extends Context.Service<
504504
{
505505
readonly reactions: ReadonlyArray<PullRequestReaction>;
506506
readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
507+
readonly editedAtByNoteId: ReadonlyMap<string, string>;
507508
readonly botLogins: ReadonlySet<string>;
508509
},
509510
GitLabPullRequestCliError
@@ -1130,12 +1131,14 @@ export const make = Effect.gen(function* () {
11301131
readonly collected: {
11311132
readonly reactions: ReadonlyArray<PullRequestReaction>;
11321133
readonly reactionsByNoteId: Map<string, ReadonlyArray<PullRequestReaction>>;
1134+
readonly editedAtByNoteId: Map<string, string>;
11331135
readonly botLogins: Set<string>;
11341136
} | null;
11351137
}): Effect.Effect<
11361138
{
11371139
readonly reactions: ReadonlyArray<PullRequestReaction>;
11381140
readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
1141+
readonly editedAtByNoteId: ReadonlyMap<string, string>;
11391142
readonly botLogins: ReadonlySet<string>;
11401143
},
11411144
GitLabPullRequestCliError
@@ -1169,10 +1172,13 @@ export const make = Effect.gen(function* () {
11691172
const collected = input.collected ?? {
11701173
reactions: decoded.success.reactions,
11711174
reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
1175+
editedAtByNoteId: new Map<string, string>(),
11721176
botLogins: new Set<string>(),
11731177
};
11741178
for (const [id, reactions] of decoded.success.reactionsByNoteId)
11751179
collected.reactionsByNoteId.set(id, reactions);
1180+
for (const [id, editedAt] of decoded.success.editedAtByNoteId)
1181+
collected.editedAtByNoteId.set(id, editedAt);
11761182
for (const login of decoded.success.botLogins) collected.botLogins.add(login);
11771183
return decoded.success.nextCursor === null || input.page >= CONVERSATION_PAGES
11781184
? Effect.succeed(collected)

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,12 @@ describe("optional activity reads", () => {
500500
listCommits: () => Effect.succeed([commit]),
501501
listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),
502502
listReactions: () =>
503-
Effect.succeed({ reactions: [], reactionsByNoteId: new Map(), botLogins: new Set<string>() }),
503+
Effect.succeed({
504+
reactions: [],
505+
reactionsByNoteId: new Map(),
506+
editedAtByNoteId: new Map(),
507+
botLogins: new Set<string>(),
508+
}),
504509
};
505510
const context = {
506511
operation: "execute" as const,
@@ -547,6 +552,46 @@ describe("optional activity reads", () => {
547552
}),
548553
);
549554

555+
it.effect("dates edited comments in the conversation and in threads", () =>
556+
Effect.gen(function* () {
557+
const editedAt = "2026-07-02T00:00:00Z";
558+
const provider = yield* make.pipe(
559+
Effect.provide(
560+
Layer.mock(GitLabPullRequestCli.GitLabPullRequestCli)({
561+
...reads,
562+
listDiscussions: () =>
563+
Effect.succeed({
564+
threads: [
565+
{
566+
id: "d1",
567+
path: "src/a.ts",
568+
line: 1,
569+
side: "right" as const,
570+
isResolved: false,
571+
isOutdated: false,
572+
comments: [comment],
573+
},
574+
],
575+
truncated: false,
576+
}),
577+
listReactions: () =>
578+
Effect.succeed({
579+
reactions: [],
580+
reactionsByNoteId: new Map(),
581+
editedAtByNoteId: new Map([[comment.id, editedAt]]),
582+
botLogins: new Set<string>(),
583+
}),
584+
}),
585+
),
586+
);
587+
588+
const activity = yield* provider.getChangeRequestActivity(reference);
589+
590+
expect(activity.comments[0]?.editedAt).toBe(editedAt);
591+
expect(activity.reviewThreads[0]?.comments[0]?.editedAt).toBe(editedAt);
592+
}),
593+
);
594+
550595
it.effect("keeps comments and commits when optional discussions and reactions fail", () =>
551596
Effect.gen(function* () {
552597
const provider = yield* make.pipe(
@@ -615,6 +660,7 @@ describe("optional activity reads", () => {
615660
Effect.succeed({
616661
reactions: [],
617662
reactionsByNoteId: new Map(),
663+
editedAtByNoteId: new Map(),
618664
botLogins: new Set([bot.login.toUpperCase()]),
619665
}),
620666
}),

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,13 +334,18 @@ export const make = Effect.gen(function* () {
334334
recoverRead(cli.listReactions(input), {
335335
reactions: [] as ReadonlyArray<PullRequestReaction>,
336336
reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
337+
editedAtByNoteId: new Map<string, string>(),
337338
botLogins: new Set<string>(),
338339
}),
339340
],
340341
{ concurrency: 4 },
341342
).pipe(
342343
Effect.mapError(fail("getChangeRequestActivity")),
343344
Effect.map(([notes, commits, discussions, awards]): ProviderChangeRequestActivity => {
345+
const edited = (id: string) => {
346+
const editedAt = awards.editedAtByNoteId.get(id);
347+
return editedAt === undefined ? {} : { editedAt };
348+
};
344349
const botLogins = new Set([...awards.botLogins].map((login) => login.toLowerCase()));
345350
const withBotFlag = (author: PullRequestActor | null) =>
346351
author !== null && botLogins.has(author.login.toLowerCase())
@@ -350,6 +355,7 @@ export const make = Effect.gen(function* () {
350355
reactions: awards.reactions,
351356
comments: notes.comments.map((comment) => ({
352357
...comment,
358+
...edited(comment.id),
353359
author: withBotFlag(comment.author),
354360
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
355361
})),
@@ -359,6 +365,7 @@ export const make = Effect.gen(function* () {
359365
...thread,
360366
comments: thread.comments.map((comment) => ({
361367
...comment,
368+
...edited(comment.id),
362369
author: withBotFlag(comment.author),
363370
reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
364371
})),

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

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

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

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ export const AWARD_EMOJI_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!, $
801801
awardEmoji { nodes { name user { username } } }
802802
notes(first: 100, after: $cursor) {
803803
pageInfo { hasNextPage endCursor }
804-
nodes { id author { username bot } awardEmoji { nodes { name user { username } } } }
804+
nodes { id author { username bot } lastEditedAt lastEditedBy { username } resolved awardEmoji { nodes { name user { username } } } }
805805
}
806806
}
807807
}
@@ -853,6 +853,15 @@ const RawAwardEmojiPageSchema = Schema.Struct({
853853
Schema.NullOr(
854854
Schema.Struct({
855855
id: Schema.optional(Schema.NullOr(Schema.String)),
856+
lastEditedAt: Schema.optional(Schema.NullOr(Schema.String)),
857+
lastEditedBy: Schema.optional(
858+
Schema.NullOr(
859+
Schema.Struct({
860+
username: Schema.optional(Schema.NullOr(Schema.String)),
861+
}),
862+
),
863+
),
864+
resolved: Schema.optional(Schema.NullOr(Schema.Boolean)),
856865
// REST note authors carry no bot flag; GraphQL's does.
857866
author: Schema.optional(
858867
Schema.NullOr(
@@ -916,6 +925,7 @@ function noteIdOf(gid: string | null | undefined): string | null {
916925
export interface GitLabAwardEmojiPage {
917926
readonly reactions: ReadonlyArray<PullRequestReaction>;
918927
readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
928+
readonly editedAtByNoteId: ReadonlyMap<string, string>;
919929
readonly botLogins: ReadonlySet<string>;
920930
readonly nextCursor: string | null;
921931
}
@@ -931,6 +941,7 @@ export function decodeAwardEmojiJson(
931941
const viewer = trimmed(data.currentUser?.username);
932942
const mergeRequest = data.project?.mergeRequest;
933943
const reactionsByNoteId = new Map<string, ReadonlyArray<PullRequestReaction>>();
944+
const editedAtByNoteId = new Map<string, string>();
934945
const botLogins = new Set<string>();
935946
for (const node of mergeRequest?.notes?.nodes ?? []) {
936947
const author = trimmed(node?.author?.username);
@@ -939,11 +950,22 @@ export function decodeAwardEmojiJson(
939950
if (id === null) continue;
940951
const reactions = toReactions(node?.awardEmoji, viewer);
941952
if (reactions.length > 0) reactionsByNoteId.set(id, reactions);
953+
// Resolving a thread moves lastEditedAt on every note in it; only lastEditedBy marks a
954+
// text edit, and a resolved note's stamp may be the resolve rather than that edit.
955+
const editedAt = trimmed(node?.lastEditedAt);
956+
if (
957+
editedAt !== null &&
958+
trimmed(node?.lastEditedBy?.username) !== null &&
959+
node?.resolved !== true
960+
) {
961+
editedAtByNoteId.set(id, editedAt);
962+
}
942963
}
943964
const pageInfo = mergeRequest?.notes?.pageInfo;
944965
return Result.succeed({
945966
reactions: toReactions(mergeRequest?.awardEmoji, viewer),
946967
reactionsByNoteId,
968+
editedAtByNoteId,
947969
botLogins,
948970
nextCursor: pageInfo?.hasNextPage === true ? (trimmed(pageInfo.endCursor) ?? null) : null,
949971
});

0 commit comments

Comments
 (0)