From db8aa305efda513a5ff0f2ee3bf2b11c7eeb25fc Mon Sep 17 00:00:00 2001 From: Max schwenk Date: Mon, 16 Nov 2026 15:40:49 -0500 Subject: [PATCH] fix(server): a watched PR the merge queue drops wakes the agent GitHub's merge queue can take a PR out (merge conflict with the queue, failed queue checks) without touching its head, checks or comments, and the PR stays open. The watch saw nothing, so an agent waiting on the queue was never told. The GitHub detail read now asks for the latest RemovedFromMergeQueueEvent and the watch fingerprint counts them, both github.com only like isRequired. A removal after the watch began that the agent did not make wakes it once with the reason; the queue's own "merged" removal is ignored. --- .../PullRequestWatchReactor.ts | 3 +- .../orchestration-v2/pullRequestWatch.test.ts | 34 +++++++++++ .../src/orchestration-v2/pullRequestWatch.ts | 32 +++++++++- .../src/pullRequest/PullRequestService.ts | 3 + packages/contracts/src/pullRequest.ts | 15 +++++ packages/contracts/src/threadPullRequest.ts | 2 + .../src/server/PullRequestProvider.ts | 2 + .../src/server/GitHubPullRequestApi.ts | 4 +- .../src/server/gitHubPullRequestJson.test.ts | 61 +++++++++++++++++++ .../src/server/gitHubPullRequestJson.ts | 29 +++++++++ .../src/server/pullRequestBatches.graphql | 12 +++- .../src/server/pullRequestBatches.graphql.ts | 17 +++++- .../src/server/pullRequestReads.graphql | 15 +++++ .../src/server/pullRequestReads.graphql.ts | 52 +++++++++++++--- 14 files changed, 262 insertions(+), 19 deletions(-) diff --git a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts index 864befdcdbe15..86f5ce7982a13 100644 --- a/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts +++ b/apps/server/src/orchestration-v2/PullRequestWatchReactor.ts @@ -186,7 +186,8 @@ function watchesEqual(left: ThreadPullRequestWatch, right: ThreadPullRequestWatc left.remarkIds.join("\n") === right.remarkIds.join("\n") && left.conflicting === right.conflicting && left.wakes === right.wakes && - left.checksAwaitedSince === right.checksAwaitedSince + left.checksAwaitedSince === right.checksAwaitedSince && + left.mergeQueueRemovedAt === right.mergeQueueRemovedAt ); } diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts index 5d00e7a496849..8e8052d3adf87 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.test.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.test.ts @@ -518,6 +518,40 @@ describe("evaluatePullRequestWatch", () => { ); }); + it("tells the agent once when the merge queue takes it out, not for older or its own removals", () => { + const removed = (at: string, by = "github-merge-queue"): Partial => ({ + mergeQueueRemoval: { at, reason: "merge_conflict", by }, + }); + const first = evaluatePullRequestWatch( + watch(), + detail(removed("2026-10-02T12:05:00Z")), + noRemarks, + ); + assert.deepEqual(first.changes, [{ kind: "left-merge-queue", reason: "merge_conflict" }]); + const wake = pullRequestWatchMessage({ + number: 278, + url: "https://github.com/o/r/pull/278", + headSha: "d2bcd96b8e", + report: first, + standing: standing(), + }); + assert.include(wake.text, "- The merge queue took it out without merging: merge conflict."); + assert.equal(wake.notification.outcome, "failed"); + assert.equal(wake.notification.summary, "#278: left the merge queue"); + + const sameRemoval = detail(removed("2026-10-02T12:05:00Z")); + assert.deepEqual(evaluatePullRequestWatch(first.next, sameRemoval, noRemarks).changes, []); + const requeuedAndRemoved = detail(removed("2026-10-02T12:30:00Z")); + assert.deepEqual(evaluatePullRequestWatch(first.next, requeuedAndRemoved, noRemarks).changes, [ + { kind: "left-merge-queue", reason: "merge_conflict" }, + ]); + + const beforeWatch = detail(removed("2026-10-02T11:55:00Z")); + assert.deepEqual(evaluatePullRequestWatch(watch(), beforeWatch, noRemarks).changes, []); + const byAgent = detail(removed("2026-10-02T12:05:00Z", "Agent-User")); + assert.deepEqual(evaluatePullRequestWatch(watch(), byAgent, noRemarks).changes, []); + }); + it("does not spend the comment wake limit on check results", () => { const tired = watch({ headSha: "aaaaaaaaaa", wakes: PULL_REQUEST_WATCH_WAKE_LIMIT - 1 }); const result = evaluatePullRequestWatch( diff --git a/apps/server/src/orchestration-v2/pullRequestWatch.ts b/apps/server/src/orchestration-v2/pullRequestWatch.ts index 846c263fc9b6e..4b7a45f569e81 100644 --- a/apps/server/src/orchestration-v2/pullRequestWatch.ts +++ b/apps/server/src/orchestration-v2/pullRequestWatch.ts @@ -63,7 +63,8 @@ export type PullRequestWatchChange = | { readonly kind: "checks-passed"; readonly count: number; readonly required: boolean } | { readonly kind: "remarks"; readonly remarks: ReadonlyArray } | { readonly kind: "no-checks"; readonly minutes: number } - | { readonly kind: "conflicting" }; + | { readonly kind: "conflicting" } + | { readonly kind: "left-merge-queue"; readonly reason: string | null }; export interface PullRequestWatchReport { readonly changes: ReadonlyArray; @@ -79,7 +80,13 @@ export function evaluatePullRequestWatch( watch: ThreadPullRequestWatch, detail: Pick< PullRequestDetail, - "capabilities" | "headSha" | "checks" | "mergeability" | "viewer" | "author" + | "capabilities" + | "headSha" + | "checks" + | "mergeability" + | "viewer" + | "author" + | "mergeQueueRemoval" >, remarks: ReadonlyArray | null, now: number, @@ -185,6 +192,16 @@ export function evaluatePullRequestWatch( const conflicting = detail.mergeability === "unknown" ? toldConflict : detail.mergeability === "conflicting"; + // The queue can take a pull request out and nothing else on it changes, so the removal itself + // is the news. One from before the watch, or one the agent made itself, is not. + const removal = detail.mergeQueueRemoval ?? null; + const removedAfter = Date.parse(watch.mergeQueueRemovedAt ?? watch.startedAt); + const newRemoval = removal !== null && Date.parse(removal.at) > removedAfter ? removal : null; + if (newRemoval !== null && newRemoval.by?.toLowerCase() !== own) { + changes.push({ kind: "left-merge-queue", reason: newRemoval.reason }); + } + const mergeQueueRemovedAt = newRemoval?.at ?? watch.mergeQueueRemovedAt; + const commentsOnly = changes.length > 0 && changes.every((change) => change.kind === "remarks"); const progress = headMoved || (changes.length > 0 && !commentsOnly); const wakes = (progress ? 0 : watch.wakes) + (commentsOnly ? 1 : 0); @@ -202,6 +219,7 @@ export function evaluatePullRequestWatch( conflicting, wakes, checksAwaitedSince, + ...(mergeQueueRemovedAt === undefined ? {} : { mergeQueueRemovedAt }), }, exhausted: commentsOnly && wakes >= PULL_REQUEST_WATCH_WAKE_LIMIT, }; @@ -259,6 +277,10 @@ function changeLines( ]; case "conflicting": return [`- The branch now conflicts with ${context.baseBranch}.`]; + case "left-merge-queue": + return [ + `- The merge queue took it out without merging${change.reason === null ? "" : `: ${change.reason.replaceAll("_", " ")}`}.`, + ]; } } @@ -268,6 +290,7 @@ const SUMMARY: Record = { remarks: "new comments", "no-checks": "no checks reported", conflicting: "merge conflict", + "left-merge-queue": "left the merge queue", }; export interface PullRequestStanding extends Pick< @@ -338,7 +361,10 @@ export function pullRequestWatchMessage(input: { : "Look into each item and act on it as your task requires. This PR stays linked and watched, so do not link, watch, or list it again. End your turn when you are done, and T3 Code wakes you on the next change. When you hand the work back to the user, call unwatch_pull_request first so the thread returns to their inbox.", ].join("\n"); const failed = changes.some( - (change) => change.kind === "checks-failed" || change.kind === "conflicting", + (change) => + change.kind === "checks-failed" || + change.kind === "conflicting" || + change.kind === "left-merge-queue", ); const summary = changes.map((change) => SUMMARY[change.kind]); if (exhausted) summary.push("stopped watching"); diff --git a/apps/server/src/pullRequest/PullRequestService.ts b/apps/server/src/pullRequest/PullRequestService.ts index ae16a60a33fd8..1f02c27c0b3a6 100644 --- a/apps/server/src/pullRequest/PullRequestService.ts +++ b/apps/server/src/pullRequest/PullRequestService.ts @@ -1859,6 +1859,9 @@ export const make = Effect.gen(function* () { ...(changeRequest.workflowApprovalsRequired === undefined ? {} : { workflowApprovalsRequired: changeRequest.workflowApprovalsRequired }), + ...(changeRequest.mergeQueueRemoval === undefined + ? {} + : { mergeQueueRemoval: changeRequest.mergeQueueRemoval }), })), ), ), diff --git a/packages/contracts/src/pullRequest.ts b/packages/contracts/src/pullRequest.ts index 5a22d3b7bbd49..ea1cf2bc57613 100644 --- a/packages/contracts/src/pullRequest.ts +++ b/packages/contracts/src/pullRequest.ts @@ -595,6 +595,16 @@ export const PullRequestReportStateInput = Schema.Struct({ }); export type PullRequestReportStateInput = typeof PullRequestReportStateInput.Type; +/** A merge queue taking a pull request out without merging it. */ +export const PullRequestMergeQueueRemoval = Schema.Struct({ + at: IsoDateTime, + /** The host's reason, such as GitHub's `merge_conflict`; null when it gives none. */ + reason: Schema.NullOr(TrimmedNonEmptyString), + /** Who took it out, usually the queue's own bot; null when the host does not say. */ + by: Schema.NullOr(TrimmedNonEmptyString), +}); +export type PullRequestMergeQueueRemoval = typeof PullRequestMergeQueueRemoval.Type; + export const PullRequestDetail = Schema.Struct({ provider: SourceControlProviderKind, capabilities: PullRequestCapabilities, @@ -637,6 +647,11 @@ export const PullRequestDetail = Schema.Struct({ autoMergeMethod: Schema.optional(PullRequestMergeMethod), workflowApprovalsRequired: Schema.optional(NonNegativeInt), maintainerCanModify: Schema.optional(Schema.Boolean), + /** + * The merge queue's latest removal, when it did not merge the pull request. Null when the last + * removal merged it or there was none; absent when the host does not report merge queues. + */ + mergeQueueRemoval: Schema.optional(Schema.NullOr(PullRequestMergeQueueRemoval)), }); export type PullRequestDetail = typeof PullRequestDetail.Type; diff --git a/packages/contracts/src/threadPullRequest.ts b/packages/contracts/src/threadPullRequest.ts index 3daee9ce197e2..84e571dbf712c 100644 --- a/packages/contracts/src/threadPullRequest.ts +++ b/packages/contracts/src/threadPullRequest.ts @@ -100,6 +100,8 @@ export const ThreadPullRequestWatch = Schema.Struct({ * none did. Null once either happened; absent on watches saved before it existed. */ checksAwaitedSince: Schema.optional(Schema.NullOr(IsoDateTime)), + /** The last merge queue removal the agent was told about; absent until there is one. */ + mergeQueueRemovedAt: Schema.optional(IsoDateTime), }); export type ThreadPullRequestWatch = typeof ThreadPullRequestWatch.Type; diff --git a/packages/source-control-core/src/server/PullRequestProvider.ts b/packages/source-control-core/src/server/PullRequestProvider.ts index 0c58f64c47a1f..400997d7e144e 100644 --- a/packages/source-control-core/src/server/PullRequestProvider.ts +++ b/packages/source-control-core/src/server/PullRequestProvider.ts @@ -21,6 +21,7 @@ import type { PullRequestListState, PullRequestMergeCapabilities, PullRequestMergeMethod, + PullRequestMergeQueueRemoval, PullRequestMergeability, PullRequestOmittedFileStat, PullRequestReaction, @@ -210,6 +211,7 @@ export interface ProviderChangeRequestDetail extends ProviderChangeRequest { readonly autoMergeEnabled?: boolean; readonly autoMergeMethod?: PullRequestMergeMethod; readonly workflowApprovalsRequired?: number; + readonly mergeQueueRemoval?: PullRequestMergeQueueRemoval | null; } export interface ProviderChangeRequestActivity { diff --git a/packages/source-control-github/src/server/GitHubPullRequestApi.ts b/packages/source-control-github/src/server/GitHubPullRequestApi.ts index 6db55da028411..c1424fe5530ba 100644 --- a/packages/source-control-github/src/server/GitHubPullRequestApi.ts +++ b/packages/source-control-github/src/server/GitHubPullRequestApi.ts @@ -1461,6 +1461,7 @@ export const make = Effect.gen(function* () { number: input.number, headRef: `refs/pull/${input.number}/head`, required: asksRequired(input.host), + mergeQueue: asksRequired(input.host), requestedReviewers, }); return SourceControlRateLimit.Interactive.pipe( @@ -1744,7 +1745,8 @@ export const make = Effect.gen(function* () { (input) => { const lookup = pullRequestLookup(input); if (lookup === null) return Effect.succeed(null); - return GraphQLResolver.request(lookup, watchFingerprintResolver).pipe( + const variables = { ...lookup, mergeQueue: asksRequired(input.host) }; + return GraphQLResolver.request(variables, watchFingerprintResolver).pipe( Effect.map((result) => { const pullRequest = result.repository?.pullRequest; return pullRequest == null ? null : toPullRequestWatchFingerprint(pullRequest); diff --git a/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts b/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts index acccedcb40f38..60d559da03456 100644 --- a/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts +++ b/packages/source-control-github/src/server/gitHubPullRequestJson.test.ts @@ -433,6 +433,48 @@ describe("pull request detail decoding", () => { pullRequest?: Record, ) => expectSuccess(decodePullRequestCoreJson(coreJson(rollup, pullRequest))); + it.each([ + ["not asked for, as on Enterprise", {}, undefined], + ["never removed", { timelineItems: { nodes: [] } }, null], + [ + "removed by the queue", + { + timelineItems: { + nodes: [ + { + __typename: "RemovedFromMergeQueueEvent", + createdAt: "2026-07-05T00:00:00Z", + reason: "merge_conflict", + actor: { __typename: "Bot", login: "github-merge-queue" }, + }, + ], + }, + }, + { at: "2026-07-05T00:00:00Z", reason: "merge_conflict", by: "github-merge-queue" }, + ], + [ + "merged by the queue", + { + timelineItems: { + nodes: [ + { + __typename: "RemovedFromMergeQueueEvent", + createdAt: "2026-07-05T00:00:00Z", + reason: "merged", + actor: { __typename: "Bot", login: "github-merge-queue" }, + }, + ], + }, + }, + null, + ], + ])( + "reads the merge queue's latest removal that did not merge: %s", + (_case, pullRequest, removal) => { + expect(detailOf([], pullRequest).mergeQueueRemoval).toEqual(removal); + }, + ); + it.each([ [{}, true], [{ viewerDidAuthor: false }, false], @@ -1819,4 +1861,23 @@ describe("pull request watch fingerprints", () => { expect(summaryEdited.status).toBe(before.status); expect(replied.remarks).not.toBe(before.remarks); }); + + it("moves status when the merge queue drops the pull request, and only when asked", () => { + const pullRequest = (removals?: number) => ({ + state: "OPEN", + mergeable: "MERGEABLE", + headRefOid: "abc123", + comments: { totalCount: 0, nodes: [] }, + reviews: { totalCount: 0, nodes: [] }, + reviewThreads: { totalCount: 0 }, + commits: { nodes: [] }, + ...(removals === undefined ? {} : { timelineItems: { filteredCount: removals } }), + }); + const status = (removals?: number) => + toPullRequestWatchFingerprint(decodeWatched(pullRequest(removals))).status; + + expect(status(1)).not.toBe(status(0)); + expect(status(0)).not.toBe(status()); + expect(status()).not.toContain("queue-removals"); + }); }); diff --git a/packages/source-control-github/src/server/gitHubPullRequestJson.ts b/packages/source-control-github/src/server/gitHubPullRequestJson.ts index df4756fcc0dda..7cb2be2498221 100644 --- a/packages/source-control-github/src/server/gitHubPullRequestJson.ts +++ b/packages/source-control-github/src/server/gitHubPullRequestJson.ts @@ -18,6 +18,7 @@ import type { PullRequestLabel, PullRequestMergeCapabilities, PullRequestMergeMethod, + PullRequestMergeQueueRemoval, PullRequestOmittedFileStat, PullRequestMergeability, PullRequestReaction, @@ -1010,6 +1011,9 @@ export function toPullRequestWatchFingerprint( pr.headRefOid, stateCounts(contexts?.checkRunCountsByState ?? null), stateCounts(contexts?.statusContextCountsByState ?? null), + ...(pr.timelineItems === undefined + ? [] + : [`queue-removals:${pr.timelineItems.filteredCount}`]), ].join(" "), remarks: [ pr.comments.totalCount, @@ -1028,6 +1032,8 @@ export interface GitHubPullRequestCore extends GitHubPullRequestDetail { readonly viewerAccess: GitHubViewerAccess & GitHubRepositoryAccess; readonly comparison: GitHubBaseComparison | null; readonly checksTruncated: boolean; + /** Absent when the read did not ask, as on Enterprise servers. */ + readonly mergeQueueRemoval?: PullRequestMergeQueueRemoval | null; } type CoreRequestedReviewer = NonNullable< @@ -1036,6 +1042,28 @@ type CoreRequestedReviewer = NonNullable< >["nodes"] >[number]; +type CoreTimeline = NonNullable< + NonNullable["pullRequest"] +>["timelineItems"]; + +/** GitHub's queue also logs a removal when it merges; only one that did not merge is news. */ +function toMergeQueueRemoval( + timeline: CoreTimeline, +): Pick { + if (timeline === undefined) return {}; + const event = nodesOf(timeline).findLast( + (node) => node.__typename === "RemovedFromMergeQueueEvent", + ); + if (event === undefined || event.__typename !== "RemovedFromMergeQueueEvent") { + return { mergeQueueRemoval: null }; + } + const reason = trimmed(event.reason); + if (reason?.toLowerCase() === "merged") return { mergeQueueRemoval: null }; + return { + mergeQueueRemoval: { at: event.createdAt, reason, by: trimmed(event.actor?.login) }, + }; +} + export function toPullRequestCore(result: PullRequestCore.Result): GitHubPullRequestCore | null { const repository = result.repository; const pr = repository?.pullRequest; @@ -1098,6 +1126,7 @@ export function toPullRequestCore(result: PullRequestCore.Result): GitHubPullReq viewerCanUpdate: pr.viewerCanUpdateBranch, }, checksTruncated: contexts?.pageInfo.hasNextPage === true, + ...toMergeQueueRemoval(pr.timelineItems), }; } diff --git a/packages/source-control-github/src/server/pullRequestBatches.graphql b/packages/source-control-github/src/server/pullRequestBatches.graphql index cb0b08ee7f1d8..6dc3a0b75b82e 100644 --- a/packages/source-control-github/src/server/pullRequestBatches.graphql +++ b/packages/source-control-github/src/server/pullRequestBatches.graphql @@ -85,12 +85,22 @@ query PullRequestStackMembership($owner: String!, $name: String!, $number: Int!) # edit moves `updatedAt`, so an edit to an old comment on a long pull request is still in the page. # Reviews have no such order: an edit to a review older than the last hundred waits for the # watch's periodic full read, as do edits to comments inside review threads. -query PullRequestWatchFingerprint($owner: String!, $name: String!, $number: Int!) { +# A merge queue can drop a pull request without touching its head, checks or comments, so the +# count of queue removals is in the fingerprint too (github.com only, like isRequired). +query PullRequestWatchFingerprint( + $owner: String! + $name: String! + $number: Int! + $mergeQueue: Boolean! +) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { state mergeable headRefOid + timelineItems(itemTypes: [REMOVED_FROM_MERGE_QUEUE_EVENT]) @include(if: $mergeQueue) { + filteredCount + } comments(first: 100, orderBy: { field: UPDATED_AT, direction: DESC }) { totalCount nodes { diff --git a/packages/source-control-github/src/server/pullRequestBatches.graphql.ts b/packages/source-control-github/src/server/pullRequestBatches.graphql.ts index 31b8863f4125c..a035917c476a0 100644 --- a/packages/source-control-github/src/server/pullRequestBatches.graphql.ts +++ b/packages/source-control-github/src/server/pullRequestBatches.graphql.ts @@ -270,6 +270,13 @@ export declare namespace PullRequestStackMembership { export type Result = typeof PullRequestStackMembership.result.Type } +/** The connection type for PullRequestTimelineItems. */ +export const PullRequestTimelineItemsConnection = Schema.Struct({ + /** Identifies the count of items after applying `before` and `after` filters. */ + filteredCount: Shared.Int +}) +export interface PullRequestTimelineItemsConnection extends Schema.Struct.Type {} + /** Represents a comment on an Issue. */ export const IssueComment = Schema.Struct({ /** The moment the editor made the last edit */ @@ -372,6 +379,8 @@ export const PullRequestWatchFingerprintRepositoryPullRequestPullRequest = Schem mergeable: GraphQL.enumLiterals(Shared.MergeableState.literals), /** Identifies the oid of the head ref associated with the pull request, even if the ref has been deleted. */ headRefOid: Shared.GitObjectID, + /** A list of events, comments, commits, etc. associated with the pull request. */ + timelineItems: Schema.optionalKey(PullRequestTimelineItemsConnection), /** A list of comments associated with the pull request. */ comments: IssueCommentConnection, /** A list of reviews associated with the pull request. */ @@ -396,17 +405,19 @@ export const PullRequestWatchFingerprint = GraphQL.query("PullRequestWatchFinger variables: [ { name: "owner", body: "String!" }, { name: "name", body: "String!" }, - { name: "number", body: "Int!" } + { name: "number", body: "Int!" }, + { name: "mergeQueue", body: "Boolean!" } ], selections: [ - { 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}}}}}}}}"] } + { name: "repository", body: ["(owner:$", "owner", " name:$", "name", "){pullRequest(number:$", "number", "){state mergeable headRefOid timelineItems(itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){filteredCount}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}}}}}}}}"] } ], fragments: [] }, variables: { owner: Schema.String, name: Schema.String, - number: Shared.Int + number: Shared.Int, + mergeQueue: Schema.Boolean }, result: Schema.Struct({ /** Lookup a given repository by the owner and repository name. */ diff --git a/packages/source-control-github/src/server/pullRequestReads.graphql b/packages/source-control-github/src/server/pullRequestReads.graphql index ef40a4ab46bcd..e6f79362acd80 100644 --- a/packages/source-control-github/src/server/pullRequestReads.graphql +++ b/packages/source-control-github/src/server/pullRequestReads.graphql @@ -58,6 +58,7 @@ query PullRequestCore( $number: Int! $headRef: String! $required: Boolean! + $mergeQueue: Boolean! $requestedReviewers: Int! ) { repository(owner: $owner, name: $name) { @@ -163,6 +164,20 @@ query PullRequestCore( } } } + # The merge queue's latest removal, so a watch can tell the agent one that did not merge. + # Gated like isRequired: an Enterprise server without merge queues would fail the read. + timelineItems(last: 1, itemTypes: [REMOVED_FROM_MERGE_QUEUE_EVENT]) + @include(if: $mergeQueue) { + nodes { + ... on RemovedFromMergeQueueEvent { + createdAt + reason + actor { + login + } + } + } + } } } } diff --git a/packages/source-control-github/src/server/pullRequestReads.graphql.ts b/packages/source-control-github/src/server/pullRequestReads.graphql.ts index 0a0f1aec68a3a..778ef7c7d39a6 100644 --- a/packages/source-control-github/src/server/pullRequestReads.graphql.ts +++ b/packages/source-control-github/src/server/pullRequestReads.graphql.ts @@ -397,6 +397,42 @@ export const PullRequestCoreRepositoryPullRequestCommitsPullRequestCommitConnect }) export interface PullRequestCoreRepositoryPullRequestCommitsPullRequestCommitConnection extends Schema.Struct.Type {} +/** Represents an object which can take actions on GitHub. Typically a User or Bot. */ +export const Actor = Schema.Struct({ + __typename: GraphQL.otherTypename()([]), + /** The username of the actor. */ + login: Schema.String +}) +export interface Actor extends Schema.Struct.Type {} + +/** Represents a 'removed_from_merge_queue' event on a given pull request. */ +export const RemovedFromMergeQueueEvent = Schema.Struct({ + __typename: Schema.Literal("RemovedFromMergeQueueEvent"), + /** Identifies the date and time when the object was created. */ + createdAt: Shared.DateTime, + /** The reason this pull request was removed from the queue. */ + reason: Schema.NullOr(Schema.String), + /** Identifies the actor who performed the event. */ + actor: Schema.NullOr(Actor) +}) +export interface RemovedFromMergeQueueEvent extends Schema.Struct.Type {} + +/** An item in a pull request timeline */ +export const PullRequestTimelineItemsOther = Schema.Struct({ + __typename: GraphQL.otherTypename()(["RemovedFromMergeQueueEvent"]) +}) +export interface PullRequestTimelineItemsOther extends Schema.Struct.Type {} + +/** The connection type for PullRequestTimelineItems. */ +export const PullRequestTimelineItemsConnection = Schema.Struct({ + /** A list of nodes. */ + nodes: Schema.NullOr(Schema.Array(Schema.NullOr(Schema.Union([ + RemovedFromMergeQueueEvent, + PullRequestTimelineItemsOther + ])))) +}) +export interface PullRequestTimelineItemsConnection extends Schema.Struct.Type {} + /** A repository pull request. */ export const PullRequestCoreRepositoryPullRequestPullRequest = Schema.Struct({ /** Identifies the pull request number. */ @@ -470,7 +506,9 @@ export const PullRequestCoreRepositoryPullRequestPullRequest = Schema.Struct({ /** A list of labels associated with the object. */ labels: Schema.NullOr(PullRequestCoreRepositoryPullRequestLabelsLabelConnection), /** A list of commits present in this pull request's head branch not present in the base branch. */ - commits: PullRequestCoreRepositoryPullRequestCommitsPullRequestCommitConnection + commits: PullRequestCoreRepositoryPullRequestCommitsPullRequestCommitConnection, + /** A list of events, comments, commits, etc. associated with the pull request. */ + timelineItems: Schema.optionalKey(PullRequestTimelineItemsConnection) }) export interface PullRequestCoreRepositoryPullRequestPullRequest extends Schema.Struct.Type {} @@ -500,10 +538,11 @@ export const PullRequestCore = GraphQL.query("PullRequestCore", { { name: "number", body: "Int!" }, { name: "headRef", body: "String!" }, { name: "required", body: "Boolean!" }, + { name: "mergeQueue", body: "Boolean!" }, { name: "requestedReviewers", body: "Int!" } ], selections: [ - { 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}}commits(last:1){nodes{commit{statusCheckRollup{contexts(first:100){nodes{__typename...", "CheckContext", "}pageInfo{hasNextPage endCursor}}}}}}}}"] } + { 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}}commits(last:1){nodes{commit{statusCheckRollup{contexts(first:100){nodes{__typename...", "CheckContext", "}pageInfo{hasNextPage endCursor}}}}}}timelineItems(last:1 itemTypes:[REMOVED_FROM_MERGE_QUEUE_EVENT])@include(if:$", "mergeQueue", "){nodes{__typename...on RemovedFromMergeQueueEvent{createdAt reason actor{__typename login}}}}}}"] } ], fragments: [ { 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}}}}}"] } @@ -515,6 +554,7 @@ export const PullRequestCore = GraphQL.query("PullRequestCore", { number: Shared.Int, headRef: Schema.String, required: Schema.Boolean, + mergeQueue: Schema.Boolean, requestedReviewers: Shared.Int }, result: Schema.Struct({ @@ -1152,14 +1192,6 @@ export const UserConnection = Schema.Struct({ }) export interface UserConnection extends Schema.Struct.Type {} -/** Represents an object which can take actions on GitHub. Typically a User or Bot. */ -export const Actor = Schema.Struct({ - __typename: GraphQL.otherTypename()([]), - /** The username of the actor. */ - login: Schema.String -}) -export interface Actor extends Schema.Struct.Type {} - /** A request for a user to review a pull request. */ export const ReviewerCandidatesRepositoryPullRequestReviewRequestsNodesReviewRequest = Schema.Struct({ /** The reviewer that is requested. */