Skip to content
TypeScript

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

Alex494660278460
diff --git a/apps/server/src/pullRequest/PullRequestService.test.ts b/apps/server/src/pullRequest/PullRequestService.test.ts
index bd0a0cd42e5..26093ad1979 100644
--- a/apps/server/src/pullRequest/PullRequestService.test.ts
+++ b/apps/server/src/pullRequest/PullRequestService.test.ts
@@ -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: [
diff --git a/apps/server/src/pullRequest/PullRequestService.ts b/apps/server/src/pullRequest/PullRequestService.ts
index db6b8424a8f..454733320da 100644
--- a/apps/server/src/pullRequest/PullRequestService.ts
+++ b/apps/server/src/pullRequest/PullRequestService.ts
@@ -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 ||