@devries-cameron20 / t3code Mirror · read-only / commits / dbaef808d5
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 21, 18:30 UTC

fix(server): wake PR watches when the merge queue drops a pull request (#24141)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

Victor committed Nov 12, 2026 at 17:05 UTC dbaef808d547126a3e8605af3b1c016587846d7e
17 files changed +375 -14
apps/server/src/orchestration-v2/PullRequestWatchReactor.ts
+1
@@ -202,6 +202,7 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc
202 left.remarksThrough === right.remarksThrough &&
203 left.remarkIds.join("\n") === right.remarkIds.join("\n") &&
204 left.conflicting === right.conflicting &&
205 + left.mergeQueueRemovalId === right.mergeQueueRemovalId &&
206 left.wakes === right.wakes &&
207 left.awaitingBaseline === right.awaitingBaseline &&
208 left.checksAwaitedSince === right.checksAwaitedSince
apps/server/src/orchestration-v2/pullRequestWatch.test.ts
+74
@@ -725,6 +725,80 @@ describe("evaluatePullRequestWatch", () => {
725 );
726 });
727
728 + it("reports each merge queue removal once while the head checks stay green", () => {
729 + const green = detail({ checks: [check("test", "success")] });
730 + const watching = evaluatePullRequestWatch(watch(), green, noRemarks).next;
731 + const removed = (id: string, removedAt: string) =>
732 + detail({ ...green, mergeQueueRemoval: { id, removedAt, reason: "Merge conflict" } });
733 +
734 + const dropped = removed("first", "2026-10-02T12:10:00Z");
735 + const first = evaluatePullRequestWatch(watching, dropped, noRemarks);
736 + assert.deepEqual(first.changes, [{ kind: "merge-queue-removed", reason: "Merge conflict" }]);
737 + const wake = pullRequestWatchMessage({
738 + number: 1,
739 + url: "https://github.com/o/r/pull/1",
740 + baseBranch: "main",
741 + headSha: first.next.headSha,
742 + report: first,
743 + });
744 + assert.deepEqual(wake.notification, {
745 + source: { kind: "monitor" },
746 + outcome: "failed",
747 + summary: "#1: removed from merge queue",
748 + });
749 + assert.deepEqual(evaluatePullRequestWatch(first.next, dropped, noRemarks).changes, []);
750 + // A read without queue news keeps the removal already told.
751 + const quiet = evaluatePullRequestWatch(first.next, green, noRemarks);
752 + assert.deepEqual(evaluatePullRequestWatch(quiet.next, dropped, noRemarks).changes, []);
753 +
754 + const again = removed("second", "2026-10-02T12:20:00Z");
755 + assert.equal(evaluatePullRequestWatch(first.next, again, noRemarks).changes.length, 1);
756 + const before = removed("before", "2026-10-02T11:00:00Z");
757 + const baseline = evaluatePullRequestWatch(
758 + watch({ headSha: watching.headSha, passed: true, passedChecks: watching.passedChecks }),
759 + before,
760 + noRemarks,
761 + );
762 + assert.deepEqual(baseline.changes, []);
763 + for (const prior of [watching, baseline.next]) {
764 + const skewed = evaluatePullRequestWatch(
765 + prior,
766 + removed("new", "2026-10-02T11:59:58Z"),
767 + noRemarks,
768 + );
769 + assert.deepEqual(skewed.changes, [{ kind: "merge-queue-removed", reason: "Merge conflict" }]);
770 + assert.deepEqual(
771 + evaluatePullRequestWatch(skewed.next, removed("new", "2026-10-02T11:59:58Z"), noRemarks)
772 + .changes,
773 + [],
774 + );
775 + }
776 + });
777 +
778 + it("reports a merge queue removal stamped in the second the watch started", () => {
779 + const watching = watch({ startedAt: "2026-10-02T12:00:00.500Z" });
780 + const removed = (removedAt: string) =>
781 + detail({ mergeQueueRemoval: { id: "first", removedAt, reason: "CI failed" } });
782 + assert.deepEqual(
783 + evaluatePullRequestWatch(watching, removed("2026-10-02T12:00:00Z"), noRemarks).changes,
784 + [{ kind: "merge-queue-removed", reason: "CI failed" }],
785 + );
786 + assert.deepEqual(
787 + evaluatePullRequestWatch(watching, removed("2026-10-02T11:59:59Z"), noRemarks).changes,
788 + [],
789 + );
790 + });
791 +
792 + it("stays quiet when the queue lets go of a pull request by merging it", () => {
793 + const watching = evaluatePullRequestWatch(watch(), detail(), noRemarks).next;
794 + const merging = detail({
795 + mergeQueueRemoval: { id: "landed", removedAt: "2026-10-02T12:10:00Z", reason: "merged" },
796 + });
797 + const read = evaluatePullRequestWatch(watching, merging, noRemarks);
798 + assert.deepEqual(read.changes, []);
799 + assert.equal(read.next.mergeQueueRemovalId, "landed");
800 + });
801 +
802 it("does not spend the comment wake limit on check results", () => {
803 const tired = watch({ headSha: "aaaaaaaaaa", wakes: PULL_REQUEST_WATCH_WAKE_LIMIT - 1 });
804 const result = evaluatePullRequestWatch(
apps/server/src/orchestration-v2/pullRequestWatch.ts
+36 -3
@@ -20,7 +20,8 @@ export type PullRequestWatchChange =
20 | { readonly kind: "checks-awaiting-approval"; readonly checks: ReadonlyArray<PullRequestCheck> }
21 | { readonly kind: "remarks"; readonly remarks: ReadonlyArray<PullRequestComment> }
22 | { readonly kind: "no-checks"; readonly minutes: number }
23 - | { readonly kind: "conflicting" };
23 + | { readonly kind: "conflicting" }
24 + | { readonly kind: "merge-queue-removed"; readonly reason: string | null };
25
26 export interface PullRequestWatchReport {
27 readonly changes: ReadonlyArray<PullRequestWatchChange>;
@@ -39,7 +40,13 @@ export function evaluatePullRequestWatch(
40 watch: ThreadPullRequestWatch,
41 detail: Pick<
42 PullRequestDetail,
42 - "capabilities" | "headSha" | "checks" | "mergeability" | "viewer" | "author"
43 + | "capabilities"
44 + | "headSha"
45 + | "checks"
46 + | "mergeability"
47 + | "viewer"
48 + | "author"
49 + | "mergeQueueRemoval"
50 >,
51 remarks: ReadonlyArray<PullRequestComment> | null,
52 now: number,
@@ -192,6 +199,23 @@ export function evaluatePullRequestWatch(
199 const conflicting =
200 detail.mergeability === "unknown" ? toldConflict : detail.mergeability === "conflicting";
201
202 + // The queue's checks run on a commit of its own, so its head can stay green after the queue
203 + // drops it. After the first read, IDs avoid comparing the server clock with the host clock.
204 + // The initial read uses whole seconds to exclude historical removals.
205 + const removal = detail.mergeQueueRemoval;
206 + if (
207 + removal !== undefined &&
208 + // Merging also records a removal, up to a second before the pull request reads as merged.
209 + removal.reason !== "merged" &&
210 + removal.id !== watch.mergeQueueRemovalId &&
211 + (watch.mergeQueueRemovalId !== undefined ||
212 + Date.parse(removal.removedAt) >= Math.floor(Date.parse(watch.startedAt) / 1000) * 1000)
213 + ) {
214 + changes.push({ kind: "merge-queue-removed", reason: removal.reason });
215 + }
216 + // Null records an empty baseline; historical IDs are saved without waking the watch.
217 + const mergeQueueRemovalId = removal?.id ?? watch.mergeQueueRemovalId ?? null;
218 +
219 const commentsOnly = changes.length > 0 && changes.every((change) => change.kind === "remarks");
220 const progress = headMoved || (changes.length > 0 && !commentsOnly);
221 const wakes = (progress ? 0 : watch.wakes) + (commentsOnly ? 1 : 0);
@@ -209,6 +233,7 @@ export function evaluatePullRequestWatch(
233 remarksThrough,
234 remarkIds,
235 conflicting,
236 + mergeQueueRemovalId,
237 wakes,
238 // Only a read that cannot be trusted to show the checks leaves the baseline to the next one.
239 ...(checksBaseline &&
@@ -278,6 +303,10 @@ function changeLines(
303 ];
304 case "conflicting":
305 return [`- The branch now conflicts with ${context.baseBranch}.`];
306 + case "merge-queue-removed":
307 + return [
308 + `- It was removed from the merge queue without merging${change.reason === null ? "" : `: ${change.reason}`}.`,
309 + ];
310 }
311 }
312
@@ -288,6 +317,7 @@ const SUMMARY: Record<PullRequestWatchChange["kind"], string> = {
317 remarks: "new comments",
318 "no-checks": "no checks reported",
319 conflicting: "merge conflict",
320 + "merge-queue-removed": "removed from merge queue",
321 };
322
323 const WATCHING_CLOSING =
@@ -348,7 +378,10 @@ export function pullRequestWatchMessage(input: {
378 : WATCHING_CLOSING,
379 ].join("\n");
380 const failed = changes.some(
351 - (change) => change.kind === "checks-failed" || change.kind === "conflicting",
381 + (change) =>
382 + change.kind === "checks-failed" ||
383 + change.kind === "conflicting" ||
384 + change.kind === "merge-queue-removed",
385 );
386 const summary = changes.map((change) => SUMMARY[change.kind]);
387 if (exhausted) summary.push("stopped watching");
apps/server/src/orchestration-v2/runtimeLayer.test.ts
+98
@@ -5033,6 +5033,104 @@ it.layer(layerTest)("OrchestrationV2LayerLive lifecycle", (it) => {
5033 }),
5034 );
5035
5036 + it.effect("persists each merge queue removal wake across reactor restarts", () =>
5037 + Effect.gen(function* () {
5038 + const orchestrator = yield* Orchestrator.OrchestratorV2;
5039 + const worker = yield* EffectWorker.OrchestrationEffectWorkerV2;
5040 + const threadId = ThreadId.make("queue-removal-watch");
5041 + const projectId = ProjectId.make("queue-removal-project");
5042 + yield* seedProject({
5043 + projectId,
5044 + title: "Queue removal",
5045 + workspaceRoot: "/workspace/watch",
5046 + defaultModelSelection: null,
5047 + createdAt: "2026-10-01T00:00:00.000Z",
5048 + });
5049 + yield* orchestrator.dispatch({
5050 + type: "thread.create",
5051 + createdBy: "user",
5052 + creationSource: "web",
5053 + commandId: CommandId.make("queue-removal-create"),
5054 + threadId,
5055 + projectId,
5056 + title: "Queue removal",
5057 + modelSelection,
5058 + runtimeMode: "full-access",
5059 + interactionMode: "default",
5060 + branch: null,
5061 + worktreePath: null,
5062 + });
5063 + yield* orchestrator.dispatch({
5064 + type: "thread.pull-request.watch",
5065 + commandId: CommandId.make("queue-removal-start"),
5066 + threadId,
5067 + host: "github.com",
5068 + repository: "pingdotgg/t3code",
5069 + number: 7,
5070 + watching: true,
5071 + link: { url: "https://github.com/pingdotgg/t3code/pull/7", source: "agent" },
5072 + });
5073 + let removal: PullRequestDetail["mergeQueueRemoval"];
5074 + const host = Layer.mergeAll(
5075 + NodeServices.layer,
5076 + NodeCrypto.layer,
5077 + Layer.mock(PullRequestService.PullRequestService)({
5078 + watchFingerprint: () =>
5079 + Effect.succeed({ status: removal?.id ?? "green", remarks: "none" }),
5080 + invalidate: () => Effect.void,
5081 + detail: () =>
5082 + Effect.succeed({
5083 + ...watchedPullRequestDetail({ projectId, number: 7, at: "2026-10-02T12:00:00.000Z" }),
5084 + checks: [{ name: "lint", status: "success", description: null, url: null }],
5085 + ...(removal === undefined ? {} : { mergeQueueRemoval: removal }),
5086 + }),
5087 + activity: () =>
5088 + Effect.succeed({
5089 + comments: [],
5090 + commentCount: 0,
5091 + commentsTruncated: false,
5092 + reviewThreads: [],
5093 + commits: [],
5094 + }),
5095 + }),
5096 + );
5097 + const reactor = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
5098 + yield* reactor.sweep;
5099 + yield* worker.drain();
5100 + removal = {
5101 + id: "first",
5102 + removedAt: "2000-01-01T00:00:00Z",
5103 + reason: "Required checks failed",
5104 + };
5105 + yield* reactor.sweep;
5106 + yield* worker.drain();
5107 + const persisted = (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch;
5108 + assert.equal(persisted?.mergeQueueRemovalId, "first");
5109 + const restarted = yield* PullRequestWatchReactor.make.pipe(Effect.provide(host));
5110 + yield* restarted.sweep;
5111 + yield* worker.drain();
5112 + removal = { ...removal, id: "second" };
5113 + yield* restarted.sweep;
5114 + yield* worker.drain();
5115 + yield* restarted.sweep;
5116 + yield* worker.drain();
5117 + const { messages } = yield* orchestrator.getThreadRecords(threadId, ["messages"]);
5118 + const removals = messages.filter(
5119 + (message) => message.notification?.summary === "#7: removed from merge queue",
5120 + );
5121 + assert.lengthOf(removals, 2);
5122 + for (const message of removals) {
5123 + assert.equal(message.notification?.outcome, "failed");
5124 + assert.include(message.text, "Required checks failed");
5125 + }
5126 + assert.equal(
5127 + (yield* orchestrator.getThreadShell(threadId))?.pullRequests?.[0]?.watch
5128 + ?.mergeQueueRemovalId,
5129 + "second",
5130 + );
5131 + }),
5132 + );
5133 +
5134 it.effect.each([
5135 "single page",
5136 "paginated",
apps/server/src/pullRequest/PullRequestService.test.ts
+21
@@ -3431,6 +3431,27 @@ it.effect(
3431 }),
3432 );
3433
3434 +it.effect("preserves merge queue removal details from the provider", () =>
3435 + Effect.gen(function* () {
3436 + const removal = { id: "RMQE_1", removedAt: "2026-07-02T00:00:00Z", reason: "CI failed" };
3437 + const service = yield* makeService({
3438 + projects: [project({ id: "p1", title: "web", workspaceRoot: "/a", repository: "acme/web" })],
3439 + providers: [
3440 + fakePullRequestProvider(SourceControlProviderKind.make("github"), {
3441 + getChangeRequest: () =>
3442 + Effect.succeed({ ...hostedChangeRequest("body"), mergeQueueRemoval: removal }),
3443 + }),
3444 + ],
3445 + });
3446 + const detail = yield* service.detail({
3447 + projectId: "p1" as ProjectId,
3448 + repository: "acme/web",
3449 + number: 1,
3450 + });
3451 + assert.deepStrictEqual(detail.mergeQueueRemoval, removal);
3452 + }),
3453 +);
3454 +
3455 it.effect("notifies linked threads when detail changes draft status in either direction", () =>
3456 Effect.gen(function* () {
3457 let isDraft = true;
apps/server/src/pullRequest/PullRequestService.ts
+3
@@ -1908,6 +1908,9 @@ export const make = Effect.gen(function* () {
1908 ...(changeRequest.workflowApprovalsRequired === undefined
1909 ? {}
1910 : { workflowApprovalsRequired: changeRequest.workflowApprovalsRequired }),
1911 + ...(changeRequest.mergeQueueRemoval === undefined
1912 + ? {}
1913 + : { mergeQueueRemoval: changeRequest.mergeQueueRemoval }),
1914 })),
1915 ),
1916 ),
docs/user/source-control.md
+2 -1
@@ -328,7 +328,8 @@ review is terminal. An open or unsynced link keeps it active.
328 Ask the agent to watch, monitor, or babysit a pull request and it calls `watch_pull_request`. While
329 the thread is active, the server checks the pull request every two minutes and wakes the agent when a
330 check fails or waits for a maintainer's approval, the required checks pass, someone else comments or reviews, or the branch starts to
331 -conflict. Threads in a project that watch the same pull request share one check. On GitHub, a check
331 +conflict. On github.com it also wakes the agent, with GitHub's reason, when the merge queue drops
332 +the pull request without merging it. Threads in a project that watch the same pull request share one check. On GitHub, a check
333 first asks whether anything changed and reads the pull request only when it did, which keeps
334 watching inside GitHub's rate limit. Comments from your own account do not wake it. Watching ends
335 when the pull request merges or closes, after 10 wakes in a row that bring only comments, after 8
packages/contracts/src/pullRequest.ts
+10
@@ -619,6 +619,14 @@ export const PullRequestReportStateInput = Schema.Struct({
619 });
620 export type PullRequestReportStateInput = typeof PullRequestReportStateInput.Type;
621
622 +/** The host's merge queue letting go of a pull request without merging it, newest first. */
623 +export const PullRequestMergeQueueRemoval = Schema.Struct({
624 + id: TrimmedNonEmptyString,
625 + removedAt: IsoDateTime,
626 + reason: Schema.NullOr(Schema.String),
627 +});
628 +export type PullRequestMergeQueueRemoval = typeof PullRequestMergeQueueRemoval.Type;
629 +
630 export const PullRequestDetail = Schema.Struct({
631 provider: SourceControlProviderKind,
632 capabilities: PullRequestCapabilities,
@@ -658,6 +666,8 @@ export const PullRequestDetail = Schema.Struct({
666 autoMergeEnabled: Schema.optional(Schema.Boolean),
667 autoMergeMethod: Schema.optional(PullRequestMergeMethod),
668 workflowApprovalsRequired: Schema.optional(NonNegativeInt),
669 + /** Absent where the host has no merge queue or does not report one. */
670 + mergeQueueRemoval: Schema.optional(PullRequestMergeQueueRemoval),
671 maintainerCanModify: Schema.optional(Schema.Boolean),
672 });
673 export type PullRequestDetail = typeof PullRequestDetail.Type;
packages/contracts/src/threadPullRequest.ts
+2
@@ -97,6 +97,8 @@ export const ThreadPullRequestWatch = Schema.Struct({
97 /** Reported remarks at remarksThrough, so late arrivals at that timestamp still count. */
98 remarkIds: Schema.Array(TrimmedNonEmptyString),
99 conflicting: Schema.Boolean,
100 + /** Last removal seen; null after an empty read, absent before the first read. */
101 + mergeQueueRemovalId: Schema.optional(Schema.NullOr(TrimmedNonEmptyString)),
102 /** Consecutive comment-only wakes; limited to prevent bot loops. */
103 wakes: NonNegativeInt,
104 /**
packages/source-control-core/src/server/PullRequestProvider.ts
+2
@@ -22,6 +22,7 @@ import type {
22 PullRequestListState,
23 PullRequestMergeCapabilities,
24 PullRequestMergeMethod,
25 + PullRequestMergeQueueRemoval,
26 PullRequestMergeability,
27 PullRequestOmittedFileStat,
28 PullRequestReaction,
@@ -212,6 +213,7 @@ export interface ProviderChangeRequestDetail extends ProviderChangeRequest {
213 readonly autoMergeEnabled?: boolean;
214 readonly autoMergeMethod?: PullRequestMergeMethod;
215 readonly workflowApprovalsRequired?: number;
216 + readonly mergeQueueRemoval?: PullRequestMergeQueueRemoval;
217 }
218
219 export interface ProviderChangeRequestActivity {
packages/source-control-github/src/server/GitHubPullRequestApi.ts
+5 -1
@@ -1509,6 +1509,7 @@ export const make = Effect.gen(function* () {
1509 headRef: `refs/pull/${input.number}/head`,
1510 required: asksRequired(input.host),
1511 requestedReviewers,
1512 + mergeQueue: input.host.toLowerCase() === "github.com",
1513 })
1514 .pipe(toleratingMissingPullRef(decodePullRequestCore));
1515 return SourceControlRateLimit.Interactive.pipe(
@@ -1793,7 +1794,10 @@ export const make = Effect.gen(function* () {
1794 (input) => {
1795 const lookup = pullRequestLookup(input);
1796 if (lookup === null) return Effect.succeed(null);
1796 - return GraphQLResolver.request(lookup, watchFingerprintResolver).pipe(
1797 + return GraphQLResolver.request(
1798 + { ...lookup, mergeQueue: input.host.toLowerCase() === "github.com" },
1799 + watchFingerprintResolver,
1800 + ).pipe(
1801 Effect.map((result) => {
1802 const pullRequest = result.repository?.pullRequest;
1803 return pullRequest == null ? null : toPullRequestWatchFingerprint(pullRequest);
packages/source-control-github/src/server/gitHubPullRequestJson.test.ts
+35 -2
@@ -559,6 +559,22 @@ describe("pull request detail decoding", () => {
559 expect(detailOf([], { autoMergeRequest: null }).autoMergeEnabled).toBe(false);
560 });
561
562 + it("reads the newest merge queue removal, and none where the queue was not asked about", () => {
563 + const removal = {
564 + __typename: "RemovedFromMergeQueueEvent",
565 + id: "RMQE_1",
566 + createdAt: "2026-07-05T00:00:00Z",
567 + reason: "Required status checks failed",
568 + };
569 + expect(detailOf([], { mergeQueueRemovals: { nodes: [removal] } }).mergeQueueRemoval).toEqual({
570 + id: "RMQE_1",
571 + removedAt: "2026-07-05T00:00:00Z",
572 + reason: "Required status checks failed",
573 + });
574 + expect(detailOf([], { mergeQueueRemovals: { nodes: [] } }).mergeQueueRemoval).toBeUndefined();
575 + expect(detailOf([]).mergeQueueRemoval).toBeUndefined();
576 + });
577 +
578 it("shows a re-running check once, as the run that is happening now", () => {
579 const detail = detailOf([
580 inWorkflow({
@@ -1753,12 +1769,14 @@ describe("pull request lookups", () => {
1769 });
1770
1771 describe("pull request watch fingerprints", () => {
1756 - it("moves status with checks and remarks with comments, each without the other", () => {
1772 + it("moves status with checks and queue removals, and remarks with comments, not across", () => {
1773 const pullRequest = (input: {
1774 readonly running: number;
1775 readonly failed: number;
1776 readonly commentEditedAt: string | null;
1777 readonly reviews: number;
1778 + readonly removals: number;
1779 + readonly timelineItems: number;
1780 }) => ({
1781 state: "OPEN",
1782 mergeable: "MERGEABLE",
@@ -1766,6 +1784,7 @@ describe("pull request watch fingerprints", () => {
1784 comments: { totalCount: 1, nodes: [{ lastEditedAt: input.commentEditedAt }] },
1785 reviews: { totalCount: input.reviews, nodes: [] },
1786 reviewThreads: { totalCount: 0 },
1787 + mergeQueueRemovals: { totalCount: input.timelineItems, filteredCount: input.removals },
1788 commits: {
1789 nodes: [
1790 {
@@ -1787,7 +1806,14 @@ describe("pull request watch fingerprints", () => {
1806 });
1807 const fingerprint = (input: Parameters<typeof pullRequest>[0]) =>
1808 toPullRequestWatchFingerprint(decodeWatched(pullRequest(input)));
1790 - const base = { running: 2, failed: 0, commentEditedAt: null, reviews: 1 };
1809 + const base = {
1810 + running: 2,
1811 + failed: 0,
1812 + commentEditedAt: null,
1813 + reviews: 1,
1814 + removals: 0,
1815 + timelineItems: 3,
1816 + };
1817 const before = fingerprint(base);
1818 const checkFinished = fingerprint({ ...base, running: 1, failed: 1 });
1819 const summaryEdited = fingerprint({ ...base, commentEditedAt: "2026-10-05T23:47:43Z" });
@@ -1798,5 +1824,12 @@ describe("pull request watch fingerprints", () => {
1824 expect(summaryEdited.remarks).not.toBe(before.remarks);
1825 expect(summaryEdited.status).toBe(before.status);
1826 expect(replied.remarks).not.toBe(before.remarks);
1827 + // Queued and dropped between two passes leaves the head and its checks as they were.
1828 + const dropped = fingerprint({ ...base, removals: 1, timelineItems: 5 });
1829 + expect(dropped.status).not.toBe(before.status);
1830 + expect(dropped.remarks).toBe(before.remarks);
1831 + // GitHub's totalCount counts every timeline item, whatever itemTypes asks for.
1832 + const queued = fingerprint({ ...base, timelineItems: 4 });
1833 + expect(queued.status).toBe(before.status);
1834 });
1835 });
packages/source-control-github/src/server/gitHubPullRequestJson.ts
+13
@@ -18,6 +18,7 @@ import type {
18 PullRequestLabel,
19 PullRequestMergeCapabilities,
20 PullRequestMergeMethod,
21 + PullRequestMergeQueueRemoval,
22 PullRequestOmittedFileStat,
23 PullRequestMergeability,
24 PullRequestReaction,
@@ -1014,6 +1015,7 @@ export function toPullRequestWatchFingerprint(
1015 pr.headRefOid,
1016 stateCounts(contexts?.checkRunCountsByState ?? null),
1017 stateCounts(contexts?.statusContextCountsByState ?? null),
1018 + pr.mergeQueueRemovals?.filteredCount ?? 0,
1019 ].join(" "),
1020 remarks: [
1021 pr.comments.totalCount,
@@ -1026,6 +1028,7 @@ export function toPullRequestWatchFingerprint(
1028 }
1029
1030 export interface GitHubPullRequestCore extends GitHubPullRequestDetail {
1031 + readonly mergeQueueRemoval?: PullRequestMergeQueueRemoval;
1032 readonly maintainerCanModify: boolean;
1033 readonly canEditMaintainerEdits: boolean;
1034 readonly reviewRequestTeams: ReadonlyArray<PullRequestActor>;
@@ -1045,7 +1048,17 @@ export function toPullRequestCore(result: PullRequestCore.Result): GitHubPullReq
1048 const pr = repository?.pullRequest;
1049 if (repository == null || pr == null) return null;
1050 const contexts = nodesOf(pr.commits)[0]?.commit.statusCheckRollup?.contexts;
1051 + const removal = nodesOf(pr.mergeQueueRemovals).at(-1);
1052 return {
1053 + ...(removal === undefined || !("id" in removal)
1054 + ? {}
1055 + : {
1056 + mergeQueueRemoval: {
1057 + id: removal.id,
1058 + removedAt: removal.createdAt,
1059 + reason: trimmed(removal.reason),
1060 + },
1061 + }),
1062 reviewRequestTeams: nodesOf(pr.reviewRequests).flatMap(
1063 ({ requestedReviewer }) => toRequestedTeam(requestedReviewer) ?? [],
1064 ),
packages/source-control-github/src/server/pullRequestBatches.graphql
+11 -1
@@ -85,7 +85,12 @@ query PullRequestStackMembership($owner: String!, $name: String!, $number: Int!)
85 # edit moves `updatedAt`, so an edit to an old comment on a long pull request is still in the page.
86 # Reviews have no such order: an edit to a review older than the last hundred waits for the
87 # watch's periodic full read, as do edits to comments inside review threads.
88 -query PullRequestWatchFingerprint($owner: String!, $name: String!, $number: Int!) {
88 +query PullRequestWatchFingerprint(
89 + $owner: String!
90 + $name: String!
91 + $number: Int!
92 + $mergeQueue: Boolean!
93 +) {
94 repository(owner: $owner, name: $name) {
95 pullRequest(number: $number) {
96 state
@@ -106,6 +111,11 @@ query PullRequestWatchFingerprint($owner: String!, $name: String!, $number: Int!
111 reviewThreads {
112 totalCount
113 }
114 + # totalCount ignores itemTypes and counts every timeline item; filteredCount honours it.
115 + mergeQueueRemovals: timelineItems(itemTypes: [REMOVED_FROM_MERGE_QUEUE_EVENT])
116 + @include(if: $mergeQueue) {
117 + filteredCount
118 + }
119 commits(last: 1) {
120 nodes {
121 commit {
packages/source-control-github/src/server/pullRequestBatches.graphql.ts
+14 -3
@@ -309,6 +309,13 @@ export const PullRequestReviewThreadConnection = Schema.Struct({
309 })
310 export interface PullRequestReviewThreadConnection extends Schema.Struct.Type<typeof PullRequestReviewThreadConnection.fields> {}
311
312 +/** The connection type for PullRequestTimelineItems. */
313 +export const PullRequestTimelineItemsConnection = Schema.Struct({
314 + /** Identifies the count of items after applying `before` and `after` filters. */
315 + filteredCount: Shared.Int
316 +})
317 +export interface PullRequestTimelineItemsConnection extends Schema.Struct.Type<typeof PullRequestTimelineItemsConnection.fields> {}
318 +
319 /** Represents a count of the state of a check run. */
320 export const CheckRunStateCount = Schema.Struct({
321 /** The state of a check run. */
@@ -378,6 +385,8 @@ export const PullRequestWatchFingerprintRepositoryPullRequestPullRequest = Schem
385 reviews: Schema.NullOr(ReviewsPullRequestReviewConnection),
386 /** The list of all review threads for this pull request. */
387 reviewThreads: PullRequestReviewThreadConnection,
388 + /** A list of events, comments, commits, etc. associated with the pull request. */
389 + mergeQueueRemovals: Schema.optionalKey(PullRequestTimelineItemsConnection),
390 /** A list of commits present in this pull request's head branch not present in the base branch. */
391 commits: PullRequestWatchFingerprintRepositoryPullRequestCommitsPullRequestCommitConnection
392 })
@@ -396,17 +405,19 @@ export const PullRequestWatchFingerprint = GraphQL.query("PullRequestWatchFinger
405 variables: [
406 { name: "owner", body: "String!" },
407 { name: "name", body: "String!" },
399 - { name: "number", body: "Int!" }
408 + { name: "number", body: "Int!" },
409 + { name: "mergeQueue", body: "Boolean!" }
410 ],
411 selections: [
402 - { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){pullRequest(number:$", "number", "){state mergeable headRefOid comments(first:100 orderBy:{field:UPDATED_AT direction:DESC}){totalCount nodes{lastEditedAt}}reviews(last:100){totalCount nodes{lastEditedAt}}reviewThreads{totalCount}commits(last:1){nodes{commit{statusCheckRollup{contexts{checkRunCountsByState{state count}statusContextCountsByState{state count}}}}}}}}"] }
412 + { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){pullRequest(number:$", "number", "){state mergeable headRefOid comments(first:100 orderBy:{field:UPDATED_AT direction:DESC}){totalCount nodes{lastEditedAt}}reviews(last:100){totalCount nodes{lastEditedAt}}reviewThreads{totalCount}mergeQueueRemovals:timelineItems(itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){filteredCount}commits(last:1){nodes{commit{statusCheckRollup{contexts{checkRunCountsByState{state count}statusContextCountsByState{state count}}}}}}}}"] }
413 ],
414 fragments: []
415 },
416 variables: {
417 owner: Schema.String,
418 name: Schema.String,
409 - number: Shared.Int
419 + number: Shared.Int,
420 + mergeQueue: Schema.Boolean
421 },
422 result: Schema.Struct({
423 /** Lookup a given repository by the owner and repository name. */
packages/source-control-github/src/server/pullRequestReads.graphql
+13
@@ -59,6 +59,7 @@ query PullRequestCore(
59 $headRef: String!
60 $required: Boolean!
61 $requestedReviewers: Int!
62 + $mergeQueue: Boolean!
63 ) {
64 repository(owner: $owner, name: $name) {
65 mergeCommitAllowed
@@ -111,6 +112,18 @@ query PullRequestCore(
112 autoMergeRequest {
113 mergeMethod
114 }
115 + # Merge queue checks run on a commit of the queue's own, so a pull request the queue drops
116 + # can keep a green head. Only this event says it left without merging.
117 + mergeQueueRemovals: timelineItems(last: 1, itemTypes: [REMOVED_FROM_MERGE_QUEUE_EVENT])
118 + @include(if: $mergeQueue) {
119 + nodes {
120 + ... on RemovedFromMergeQueueEvent {
121 + id
122 + createdAt
123 + reason
124 + }
125 + }
126 + }
127 viewerCanUpdate
128 viewerDidAuthor
129 viewerCanUpdateBranch
packages/source-control-github/src/server/pullRequestReads.graphql.ts
+35 -3
@@ -264,6 +264,34 @@ export const AutoMergeRequest = Schema.Struct({
264 })
265 export interface AutoMergeRequest extends Schema.Struct.Type<typeof AutoMergeRequest.fields> {}
266
267 +/** Represents a 'removed_from_merge_queue' event on a given pull request. */
268 +export const RemovedFromMergeQueueEvent = Schema.Struct({
269 + __typename: Schema.Literal("RemovedFromMergeQueueEvent"),
270 + /** The Node ID of the RemovedFromMergeQueueEvent object */
271 + id: Shared.ID,
272 + /** Identifies the date and time when the object was created. */
273 + createdAt: Shared.DateTime,
274 + /** The reason this pull request was removed from the queue. */
275 + reason: Schema.NullOr(Schema.String)
276 +})
277 +export interface RemovedFromMergeQueueEvent extends Schema.Struct.Type<typeof RemovedFromMergeQueueEvent.fields> {}
278 +
279 +/** An item in a pull request timeline */
280 +export const PullRequestTimelineItemsOther = Schema.Struct({
281 + __typename: GraphQL.otherTypename<Shared.Typename.PullRequestTimelineItems>()(["RemovedFromMergeQueueEvent"])
282 +})
283 +export interface PullRequestTimelineItemsOther extends Schema.Struct.Type<typeof PullRequestTimelineItemsOther.fields> {}
284 +
285 +/** The connection type for PullRequestTimelineItems. */
286 +export const PullRequestTimelineItemsConnection = Schema.Struct({
287 + /** A list of nodes. */
288 + nodes: Schema.NullOr(Schema.Array(Schema.NullOr(Schema.Union([
289 + RemovedFromMergeQueueEvent,
290 + PullRequestTimelineItemsOther
291 + ]))))
292 +})
293 +export interface PullRequestTimelineItemsConnection extends Schema.Struct.Type<typeof PullRequestTimelineItemsConnection.fields> {}
294 +
295 /** Represents a comparison between two commit revisions. */
296 export const Comparison = Schema.Struct({
297 /** The number of commits behind the base branch. */
@@ -456,6 +484,8 @@ export const PullRequestCoreRepositoryPullRequestPullRequest = Schema.Struct({
484 ])),
485 /** Returns the auto-merge request object if one exists for this pull request. */
486 autoMergeRequest: Schema.NullOr(AutoMergeRequest),
487 + /** A list of events, comments, commits, etc. associated with the pull request. */
488 + mergeQueueRemovals: Schema.optionalKey(PullRequestTimelineItemsConnection),
489 /** Check if the current viewer can update this object. */
490 viewerCanUpdate: Schema.Boolean,
491 /** Did the viewer author this comment. */
@@ -502,10 +532,11 @@ export const PullRequestCore = GraphQL.query("PullRequestCore", {
532 { name: "number", body: "Int!" },
533 { name: "headRef", body: "String!" },
534 { name: "required", body: "Boolean!" },
505 - { name: "requestedReviewers", body: "Int!" }
535 + { name: "requestedReviewers", body: "Int!" },
536 + { name: "mergeQueue", body: "Boolean!" }
537 ],
538 selections: [
508 - { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed autoMergeAllowed viewerPermission pullRequest(number:$", "number", "){number title url body state isDraft mergeable mergeStateStatus reviewDecision additions deletions changedFiles createdAt updatedAt mergedAt closedAt headRefName baseRefName headRefOid isCrossRepository maintainerCanModify headRepositoryOwner{__typename login}headRepository{nameWithOwner viewerPermission}headRef{id}author{__typename login avatarUrl...on User{id name}}autoMergeRequest{mergeMethod}viewerCanUpdate viewerDidAuthor viewerCanUpdateBranch baseRef{compare(headRef:$", "headRef", "){behindBy}}reviewRequests(first:$", "requestedReviewers", "){nodes{requestedReviewer{__typename...on User{login name}...on Bot{login}...on Team{slug combinedSlug teamName:name teamAvatarUrl:avatarUrl}}}}labels(first:100){nodes{name color description}}commits(last:1){nodes{commit{statusCheckRollup{contexts(first:100){nodes{__typename...", "CheckContext", "}pageInfo{hasNextPage endCursor}}}}}}}}"] }
539 + { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed autoMergeAllowed viewerPermission pullRequest(number:$", "number", "){number title url body state isDraft mergeable mergeStateStatus reviewDecision additions deletions changedFiles createdAt updatedAt mergedAt closedAt headRefName baseRefName headRefOid isCrossRepository maintainerCanModify headRepositoryOwner{__typename login}headRepository{nameWithOwner viewerPermission}headRef{id}author{__typename login avatarUrl...on User{id name}}autoMergeRequest{mergeMethod}mergeQueueRemovals:timelineItems(last:1 itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){nodes{__typename...on RemovedFromMergeQueueEvent{id createdAt reason}}}viewerCanUpdate viewerDidAuthor viewerCanUpdateBranch baseRef{compare(headRef:$", "headRef", "){behindBy}}reviewRequests(first:$", "requestedReviewers", "){nodes{requestedReviewer{__typename...on User{login name}...on Bot{login}...on Team{slug combinedSlug teamName:name teamAvatarUrl:avatarUrl}}}}labels(first:100){nodes{name color description}}commits(last:1){nodes{commit{statusCheckRollup{contexts(first:100){nodes{__typename...", "CheckContext", "}pageInfo{hasNextPage endCursor}}}}}}}}"] }
540 ],
541 fragments: [
542 { name: "CheckContext", body: ["on StatusCheckRollupContext{__typename...on StatusContext{context state targetUrl createdAt description isRequired(pullRequestNumber:$", "number", ")@include(if:$", "required", ")}...on CheckRun{name status conclusion startedAt completedAt detailsUrl isRequired(pullRequestNumber:$", "number", ")@include(if:$", "required", ")checkSuite{workflowRun{workflow{name}}}}}"] }
@@ -517,7 +548,8 @@ export const PullRequestCore = GraphQL.query("PullRequestCore", {
548 number: Shared.Int,
549 headRef: Schema.String,
550 required: Schema.Boolean,
520 - requestedReviewers: Shared.Int
551 + requestedReviewers: Shared.Int,
552 + mergeQueue: Schema.Boolean
553 },
554 result: Schema.Struct({
555 /** Lookup a given repository by the owner and repository name. */