fix(server): GitHub PR lookups stop probing owner-qualified heads (#13200)

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Opus 5.5 authored and GitHub committed 2026-09-22 20:50:50 -07:00
1 parent 18de6bb328
commit eafb4a9340
2 files changed
+51 -104

No files matched your search

+30 -6
View File
@@ -32,6 +32,7 @@ import {
ModelSelection,
type ProjectId,
SourceControlProviderError,
type SourceControlProviderKind,
type SourceControlWritingStyleSettings,
type ThreadId,
} from "@t3tools/contracts";
@@ -594,6 +595,26 @@ function parseCustomCommitMessage(raw: string): { subject: string; body: string
};
}
// Without the owner selector, a bare branch name also lists same-named
// branches on other forks (`main`, `patch-1`), so GitHub probes ask for a full
// page and let matchesBranchHeadContext pick the right head. gh fetches up to
// 100 in one request, and GitHub prices a first:100 connection like first:1.
const GITHUB_HEAD_BRANCH_PROBE_LIMIT = 100;
// `gh pr list --head` filters on the head ref name alone and accepts anything, so an
// `owner:branch` or `remote:branch` selector silently lists zero pull requests
// while spending a GraphQL call. Git branch names cannot contain ":", and the
// bare head branch is always among the selectors, so GitHub probes skip them and
// leave the owner check to matchesBranchHeadContext.
function probeableHeadSelectors(
providerKind: SourceControlProviderKind,
headSelectors: ReadonlyArray<string>,
): ReadonlyArray<string> {
return providerKind === "github"
? headSelectors.filter((selector) => !selector.includes(":"))
: headSelectors;
}
function appendUnique(values: string[], next: string | null | undefined): void {
const trimmed = next?.trim() ?? "";
if (trimmed.length === 0 || values.includes(trimmed)) {
@@ -1604,12 +1625,14 @@ export const make = Effect.gen(function* () {
| "isCrossRepository"
>,
) {
for (const headSelector of headContext.headSelectors) {
const pullRequests = yield* (yield* sourceControlProvider(cwd)).listChangeRequests({
const provider = yield* sourceControlProvider(cwd);
const headSelectors = probeableHeadSelectors(provider.kind, headContext.headSelectors);
for (const headSelector of headSelectors) {
const pullRequests = yield* provider.listChangeRequests({
cwd,
headSelector,
state: "open",
limit: 1,
limit: provider.kind === "github" ? GITHUB_HEAD_BRANCH_PROBE_LIMIT : 1,
});
const normalizedPullRequests = pullRequests.map(toPullRequestInfo);
@@ -1634,12 +1657,13 @@ export const make = Effect.gen(function* () {
) {
const parsedByNumber = new Map<number, PullRequestInfo>();
for (const headSelector of headContext.headSelectors) {
const pullRequests = yield* (yield* sourceControlProvider(cwd)).listChangeRequests({
const provider = yield* sourceControlProvider(cwd);
for (const headSelector of probeableHeadSelectors(provider.kind, headContext.headSelectors)) {
const pullRequests = yield* provider.listChangeRequests({
cwd,
headSelector,
state: "all",
limit: 20,
limit: provider.kind === "github" ? GITHUB_HEAD_BRANCH_PROBE_LIMIT : 20,
});
for (const pr of pullRequests.map(toPullRequestInfo)) {