fix(server): refresh linked PRs without a checkout (#17167)

This commit is contained in:
Alex authored and GitHub committed 2026-10-11 11:25:24 -07:00
1 parent f23d0084b6
commit 4946602784
2 files changed
+175 -6

No files matched your search

@@ -2566,7 +2566,145 @@ it.effect("refuses Azure cross-organization reads and writes without its checkou
}),
);
it.effect("refuses a hosted reference when nothing is checked out from that host", () =>
it.effect.each([
["github.com", "github"],
["bitbucket.org", "bitbucket"],
["codeberg.org", "forgejo"],
] as const)("reads linked PR summaries and stacks on %s without a checkout", ([host, kind]) =>
Effect.gen(function* () {
const seen: Array<{ cwd: string; repository: string; host: string }> = [];
const service = yield* makeService({
projects: [project({ id: "inbox", title: "Inbox", workspaceRoot: "/home/alex" })],
providers: [
fakeProvider(SourceControlProviderKind.make(kind), {
getChangeRequestSummary: (input) =>
Effect.sync(() => {
seen.push({ cwd: input.cwd, repository: input.repository, host: input.host });
return changeRequest(7, "2026-07-02T00:00:00Z");
}),
getChangeRequestStack: (input) =>
Effect.sync(() => {
seen.push({ cwd: input.cwd, repository: input.repository, host: input.host });
return null;
}),
}),
],
});
const reference = {
projectId: "inbox" as ProjectId,
host,
repository: "acme/api",
number: 7,
};
const summary = yield* service.summary(reference, { recoverTransientFailure: false });
const stack = yield* service.stack(reference, { includeDetails: false });
assert.strictEqual(summary.title, "Change request 7");
assert.strictEqual(summary.state, "open");
assert.strictEqual(summary.projectId, reference.projectId);
assert.strictEqual(stack, null);
assert.deepStrictEqual(seen, [
{ cwd: "/home/alex", repository: "acme/api", host },
{ cwd: "/home/alex", repository: "acme/api", host },
]);
}),
);
it.effect("prefers a matching checkout over a non-repository project's directory", () =>
Effect.gen(function* () {
const seen: string[] = [];
const service = yield* makeService({
projects: [
project({ id: "inbox", title: "Inbox", workspaceRoot: "/home/alex" }),
project({ id: "repo", title: "API", workspaceRoot: "/api", repository: "acme/api" }),
],
providers: [
fakeProvider(SourceControlProviderKind.make("github"), {
getChangeRequestSummary: (input) =>
Effect.sync(() => {
seen.push(input.cwd);
return changeRequest(7, "2026-07-02T00:00:00Z");
}),
}),
],
});
yield* service.summary(
{
projectId: "inbox" as ProjectId,
host: "github.com",
repository: "acme/api",
number: 7,
},
{ recoverTransientFailure: false },
);
assert.deepStrictEqual(seen, ["/api"]);
}),
);
it.effect("requires an explicit host for a non-repository project's linked PR", () =>
Effect.gen(function* () {
const service = yield* makeService({
projects: [project({ id: "inbox", title: "Inbox", workspaceRoot: "/home/alex" })],
providers: [fakeProvider(SourceControlProviderKind.make("github"))],
});
const error = yield* service
.summary(
{
projectId: "inbox" as ProjectId,
repository: "acme/api",
number: 7,
},
{ recoverTransientFailure: false },
)
.pipe(Effect.flip);
assert.strictEqual(error._tag, "PullRequestUnavailableError");
}),
);
it.effect("refuses a public host reference without a selected project directory", () =>
Effect.gen(function* () {
const service = yield* makeService({
projects: [],
providers: [fakeProvider(SourceControlProviderKind.make("github"))],
});
const error = yield* service
.summary(
{
projectId: "missing" as ProjectId,
host: "github.com",
repository: "acme/api",
number: 7,
},
{ recoverTransientFailure: false },
)
.pipe(Effect.flip);
assert.strictEqual(error._tag, "PullRequestUnavailableError");
}),
);
it.effect(
"requires a checkout for GitLab because its adapter does not explicitly target the host",
() =>
Effect.gen(function* () {
const service = yield* makeService({
projects: [project({ id: "inbox", title: "Inbox", workspaceRoot: "/home/alex" })],
providers: [fakeProvider(SourceControlProviderKind.make("gitlab"))],
});
const error = yield* service
.summary(
{
projectId: "inbox" as ProjectId,
host: "gitlab.com",
repository: "acme/api",
number: 7,
},
{ recoverTransientFailure: false },
)
.pipe(Effect.flip);
assert.strictEqual(error._tag, "PullRequestUnavailableError");
}),
);
it.effect("refuses a hosted reference when its provider is unavailable", () =>
Effect.gen(function* () {
const service = yield* makeService({
projects: [
@@ -902,8 +902,9 @@ export const make = Effect.gen(function* () {
* The project whose checkout and credentials serve a reference. The project's own
* repository is the default; a reference that names a `host` may instead point at any
* repository on that host. Prefer its own checkout; providers with explicit repository
* targeting can fall back to another checkout on the host. Azure derives its organization
* from the checkout, so it requires a matching repository.
* targeting can fall back to another checkout on the host. Providers with explicit host
* targeting can also use the selected project's directory for supported public hosts.
* Azure derives its organization from the checkout, so it requires a matching repository.
*/
const requireProject = (ref: PullRequestRef): Effect.Effect<SupportedProject, PullRequestError> =>
listWorkspaceProjects({ projectId: ref.projectId }).pipe(
@@ -949,9 +950,39 @@ export const make = Effect.gen(function* () {
) ??
onHost.find((candidate) => candidate.repositoryKey === null);
if (route === undefined) {
return Effect.fail(
new PullRequestUnavailableError({ reason: "provider-unsupported" }),
);
return Effect.gen(function* () {
// These providers target the repository explicitly and authenticate by host;
// a linked PR in a non-repository project still needs its snapshot refreshed.
// GitLab still selects its host from the checkout or CLI configuration.
const provider = ["github.com", "bitbucket.org", "codeberg.org"].includes(host)
? detectSourceControlProviderFromRemoteUrl(`https://${host}/${repository}.git`)
: null;
const api = provider === null ? null : registry.get(provider.kind);
if (api !== null) {
const selected = yield* projects.getShell(ref.projectId).pipe(
Effect.mapError(
(cause) =>
new PullRequestOperationError({
operation: "resolveRepository",
detail: "The selected project could not be read.",
cause,
}),
),
);
if (Option.isSome(selected)) {
return {
cursorKey: listCursorKey(host, repository),
project: selected.value,
api: withRateLimitBackoff(api, host, rateLimits),
repository,
host,
remote: normalizeGitRemoteUrl(`https://${host}/${repository}`),
repositoryKey: null,
};
}
}
return yield* new PullRequestUnavailableError({ reason: "provider-unsupported" });
});
}
return Effect.succeed(
route.repositoryKey !== null ||