feat(server): agents can watch a PR and get woken when checks, reviews, or conflicts need them (#15057)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Theo BrowneandClaude Opus 5.5 authored and GitHub committed 2026-10-03 03:08:44 -07:00
1 parent e8545b293b
commit 18b21325c3
31 files changed
+1531 -39

No files matched your search

@@ -52,7 +52,7 @@ import {
decodePullRequestActivityJson,
decodePullRequestDetailJson,
decodePullRequestCoreJson,
PULL_REQUEST_CORE_GRAPHQL_QUERY,
pullRequestCoreGraphQlQuery,
type GitHubPullRequestCore,
type GitHubPullRequestSummary,
decodePullRequestPreviewJson,
@@ -1595,7 +1595,7 @@ export const make = Effect.gen(function* () {
["-F", `number=${input.number}`],
["-f", `headRef=refs/pull/${input.number}/head`],
],
query: PULL_REQUEST_CORE_GRAPHQL_QUERY,
query: pullRequestCoreGraphQlQuery(input.host),
decode: decodePullRequestCoreJson,
}),
),
@@ -213,6 +213,8 @@ export interface ProviderChangeRequestStat {
}
export interface ProviderChangeRequestDetail extends ProviderChangeRequest {
/** The head commit, where the host's detail read reports it. */
readonly headSha?: string | null;
readonly body: string;
readonly changedFiles: number;
readonly mergedAt: string | null;
@@ -1697,6 +1697,7 @@ export const make = Effect.gen(function* () {
...(changeRequest.headRepositoryNameWithOwner === undefined
? {}
: { headRepositoryNameWithOwner: changeRequest.headRepositoryNameWithOwner }),
...(changeRequest.headSha ? { headSha: changeRequest.headSha } : {}),
baseBranch: changeRequest.baseBranch,
createdAt: changeRequest.createdAt,
updatedAt: changeRequest.updatedAt,
@@ -26,6 +26,7 @@ import {
decodeWorkflowRunApprovalsJson,
reviewThreadConversation,
REVIEW_THREADS_GRAPHQL_QUERY,
pullRequestCoreGraphQlQuery,
pullRequestSearchGraphQlQuery,
} from "./gitHubPullRequestJson.ts";
@@ -285,6 +286,25 @@ describe("pull request detail decoding", () => {
]);
});
it("keeps what branch protection requires, and asks for it on github.com only", () => {
const raw = JSON.parse(detailJson) as Record<string, unknown>;
const detail = expectSuccess(
decodePullRequestDetailJson(
JSON.stringify({
...raw,
statusCheckRollup: [
{ __typename: "CheckRun", name: "test", status: "IN_PROGRESS", isRequired: true },
{ __typename: "StatusContext", context: "bot", state: "PENDING", isRequired: false },
{ __typename: "StatusContext", context: "legacy", state: "SUCCESS" },
],
}),
),
);
expect(detail.checks.map((check) => check.required)).toEqual([true, false, undefined]);
expect(pullRequestCoreGraphQlQuery("github.com")).toContain("isRequired");
expect(pullRequestCoreGraphQlQuery("github.example.com")).not.toContain("isRequired");
});
it("keeps a workflow waiting for approval out of the passing state", () => {
const raw = JSON.parse(detailJson) as Record<string, unknown>;
const detail = expectSuccess(
@@ -93,6 +93,8 @@ const RawCheckSchema = Schema.Struct({
workflowName: Schema.optional(Schema.NullOr(Schema.String)),
startedAt: Schema.optional(Schema.NullOr(Schema.String)),
completedAt: Schema.optional(Schema.NullOr(Schema.String)),
/** Branch protection requires this check; read by the detail query on github.com only. */
isRequired: Schema.optional(Schema.NullOr(Schema.Boolean)),
});
const RawListItemSchema = Schema.Struct({
@@ -706,8 +708,15 @@ export const PULL_REQUEST_LIST_JSON_FIELDS =
export const PULL_REQUEST_DETAIL_JSON_FIELDS = `${PULL_REQUEST_LIST_JSON_FIELDS},body,changedFiles,closedAt,isCrossRepository,headRepositoryOwner,headRefOid,autoMergeRequest`;
/** Pull refs let the comparison share the detail read without first resolving a fork branch. */
export const PULL_REQUEST_CORE_GRAPHQL_QUERY = `query($owner: String!, $name: String!, $number: Int!, $headRef: String!) {
/**
* Pull refs let the comparison share the detail read without first resolving a fork branch.
* `isRequired` is asked for on github.com only: an older Enterprise server may not know it, and
* an unknown field fails the whole read.
*/
export const pullRequestCoreGraphQlQuery = (host: string) => {
const required =
host.toLowerCase() === "github.com" ? " isRequired(pullRequestNumber: $number)" : "";
return `query($owner: String!, $name: String!, $number: Int!, $headRef: String!) {
repository(owner: $owner, name: $name) {
mergeCommitAllowed squashMergeAllowed rebaseMergeAllowed viewerPermission
pullRequest(number: $number) {
@@ -727,9 +736,9 @@ export const PULL_REQUEST_CORE_GRAPHQL_QUERY = `query($owner: String!, $name: St
nodes { commit { statusCheckRollup { contexts(first: 100) {
nodes {
__typename
... on StatusContext { context state targetUrl createdAt description }
... on StatusContext { context state targetUrl createdAt description${required} }
... on CheckRun {
name status conclusion startedAt completedAt detailsUrl
name status conclusion startedAt completedAt detailsUrl${required}
checkSuite { workflowRun { workflow { name } } }
}
}
@@ -739,6 +748,7 @@ export const PULL_REQUEST_CORE_GRAPHQL_QUERY = `query($owner: String!, $name: St
}
}
}`;
};
export const PULL_REQUEST_PREVIEW_GRAPHQL_QUERY = `query($owner: String!, $name: String!, $number: Int!) {
repository(owner: $owner, name: $name) {
@@ -1468,6 +1478,7 @@ function toCheckEntries(
status: toCheckStatus(check),
description: trimmed(check.description),
url: trimmed(check.detailsUrl) ?? trimmed(check.targetUrl),
...(typeof check.isRequired === "boolean" ? { required: check.isRequired } : {}),
},
workflowName: trimmed(check.workflowName),
at: realTimestamp(check.completedAt) ?? realTimestamp(check.startedAt),