@devries-cameron20 / t3code Mirror · read-only / commits / e136e8e3d4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 03:15 UTC

fix(gitlab): edited comments wake PR watchers (#30403)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <51714798+juliusmarminge@users.noreply.github.com>

Antony committed Nov 6, 2026 at 01:32 UTC e136e8e3d4cb85a56463d449f1d3835313737e43
5 files changed +125 -2
packages/source-control-gitlab/src/server/GitLabPullRequestCli.ts
+6
@@ -504,6 +504,7 @@ export class GitLabPullRequestCli extends Context.Service<
504 {
505 readonly reactions: ReadonlyArray<PullRequestReaction>;
506 readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
507 + readonly editedAtByNoteId: ReadonlyMap<string, string>;
508 readonly botLogins: ReadonlySet<string>;
509 },
510 GitLabPullRequestCliError
@@ -1130,12 +1131,14 @@ export const make = Effect.gen(function* () {
1131 readonly collected: {
1132 readonly reactions: ReadonlyArray<PullRequestReaction>;
1133 readonly reactionsByNoteId: Map<string, ReadonlyArray<PullRequestReaction>>;
1134 + readonly editedAtByNoteId: Map<string, string>;
1135 readonly botLogins: Set<string>;
1136 } | null;
1137 }): Effect.Effect<
1138 {
1139 readonly reactions: ReadonlyArray<PullRequestReaction>;
1140 readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
1141 + readonly editedAtByNoteId: ReadonlyMap<string, string>;
1142 readonly botLogins: ReadonlySet<string>;
1143 },
1144 GitLabPullRequestCliError
@@ -1169,10 +1172,13 @@ export const make = Effect.gen(function* () {
1172 const collected = input.collected ?? {
1173 reactions: decoded.success.reactions,
1174 reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
1175 + editedAtByNoteId: new Map<string, string>(),
1176 botLogins: new Set<string>(),
1177 };
1178 for (const [id, reactions] of decoded.success.reactionsByNoteId)
1179 collected.reactionsByNoteId.set(id, reactions);
1180 + for (const [id, editedAt] of decoded.success.editedAtByNoteId)
1181 + collected.editedAtByNoteId.set(id, editedAt);
1182 for (const login of decoded.success.botLogins) collected.botLogins.add(login);
1183 return decoded.success.nextCursor === null || input.page >= CONVERSATION_PAGES
1184 ? Effect.succeed(collected)
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.test.ts
+47 -1
@@ -500,7 +500,12 @@ describe("optional activity reads", () => {
500 listCommits: () => Effect.succeed([commit]),
501 listDiscussions: () => Effect.succeed({ threads: [], truncated: false }),
502 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 + }),
509 };
510 const context = {
511 operation: "execute" as const,
@@ -547,6 +552,46 @@ describe("optional activity reads", () => {
552 }),
553 );
554
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 +
595 it.effect("keeps comments and commits when optional discussions and reactions fail", () =>
596 Effect.gen(function* () {
597 const provider = yield* make.pipe(
@@ -615,6 +660,7 @@ describe("optional activity reads", () => {
660 Effect.succeed({
661 reactions: [],
662 reactionsByNoteId: new Map(),
663 + editedAtByNoteId: new Map(),
664 botLogins: new Set([bot.login.toUpperCase()]),
665 }),
666 }),
packages/source-control-gitlab/src/server/GitLabPullRequestProvider.ts
+7
@@ -334,6 +334,7 @@ export const make = Effect.gen(function* () {
334 recoverRead(cli.listReactions(input), {
335 reactions: [] as ReadonlyArray<PullRequestReaction>,
336 reactionsByNoteId: new Map<string, ReadonlyArray<PullRequestReaction>>(),
337 + editedAtByNoteId: new Map<string, string>(),
338 botLogins: new Set<string>(),
339 }),
340 ],
@@ -341,6 +342,10 @@ export const make = Effect.gen(function* () {
342 ).pipe(
343 Effect.mapError(fail("getChangeRequestActivity")),
344 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 + };
349 const botLogins = new Set([...awards.botLogins].map((login) => login.toLowerCase()));
350 const withBotFlag = (author: PullRequestActor | null) =>
351 author !== null && botLogins.has(author.login.toLowerCase())
@@ -350,6 +355,7 @@ export const make = Effect.gen(function* () {
355 reactions: awards.reactions,
356 comments: notes.comments.map((comment) => ({
357 ...comment,
358 + ...edited(comment.id),
359 author: withBotFlag(comment.author),
360 reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
361 })),
@@ -359,6 +365,7 @@ export const make = Effect.gen(function* () {
365 ...thread,
366 comments: thread.comments.map((comment) => ({
367 ...comment,
368 + ...edited(comment.id),
369 author: withBotFlag(comment.author),
370 reactions: awards.reactionsByNoteId.get(comment.id) ?? [],
371 })),
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.test.ts
+42
@@ -544,6 +544,48 @@ describe("decodeAwardEmojiJson", () => {
544 expect(result.nextCursor).toBeNull();
545 });
546
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 +
589 it("matches the viewer's username case-insensitively, since GitLab is not consistent about case", () => {
590 const result = expectSuccess(
591 decodeAwardEmojiJson(
packages/source-control-gitlab/src/server/gitLabMergeRequestJson.ts
+23 -1
@@ -801,7 +801,7 @@ export const AWARD_EMOJI_GRAPHQL_QUERY = `query($fullPath: ID!, $iid: String!, $
801 awardEmoji { nodes { name user { username } } }
802 notes(first: 100, after: $cursor) {
803 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 } } } }
805 }
806 }
807 }
@@ -853,6 +853,15 @@ const RawAwardEmojiPageSchema = Schema.Struct({
853 Schema.NullOr(
854 Schema.Struct({
855 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)),
865 // REST note authors carry no bot flag; GraphQL's does.
866 author: Schema.optional(
867 Schema.NullOr(
@@ -916,6 +925,7 @@ function noteIdOf(gid: string | null | undefined): string | null {
925 export interface GitLabAwardEmojiPage {
926 readonly reactions: ReadonlyArray<PullRequestReaction>;
927 readonly reactionsByNoteId: ReadonlyMap<string, ReadonlyArray<PullRequestReaction>>;
928 + readonly editedAtByNoteId: ReadonlyMap<string, string>;
929 readonly botLogins: ReadonlySet<string>;
930 readonly nextCursor: string | null;
931 }
@@ -931,6 +941,7 @@ export function decodeAwardEmojiJson(
941 const viewer = trimmed(data.currentUser?.username);
942 const mergeRequest = data.project?.mergeRequest;
943 const reactionsByNoteId = new Map<string, ReadonlyArray<PullRequestReaction>>();
944 + const editedAtByNoteId = new Map<string, string>();
945 const botLogins = new Set<string>();
946 for (const node of mergeRequest?.notes?.nodes ?? []) {
947 const author = trimmed(node?.author?.username);
@@ -939,11 +950,22 @@ export function decodeAwardEmojiJson(
950 if (id === null) continue;
951 const reactions = toReactions(node?.awardEmoji, viewer);
952 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 + }
963 }
964 const pageInfo = mergeRequest?.notes?.pageInfo;
965 return Result.succeed({
966 reactions: toReactions(mergeRequest?.awardEmoji, viewer),
967 reactionsByNoteId,
968 + editedAtByNoteId,
969 botLogins,
970 nextCursor: pageInfo?.hasNextPage === true ? (trimmed(pageInfo.endCursor) ?? null) : null,
971 });