Skip to content

Commit bfa2880

Browse files
committed
fix(server): retain checkout routing for GitLab
1 parent 9547755 commit bfa2880

2 files changed

Lines changed: 36 additions & 14 deletions

File tree

‎apps/server/src/pullRequest/PullRequestService.test.ts‎

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,7 +2568,6 @@ it.effect("refuses Azure cross-organization reads and writes without its checkou
25682568

25692569
it.effect.each([
25702570
["github.com", "github"],
2571-
["gitlab.com", "gitlab"],
25722571
["bitbucket.org", "bitbucket"],
25732572
["codeberg.org", "forgejo"],
25742573
] as const)("reads linked PR summaries and stacks on %s without a checkout", ([host, kind]) =>
@@ -2577,7 +2576,7 @@ it.effect.each([
25772576
const service = yield* makeService({
25782577
projects: [project({ id: "inbox", title: "Inbox", workspaceRoot: "/home/alex" })],
25792578
providers: [
2580-
fakeProvider(kind, {
2579+
fakeProvider(SourceControlProviderKind.make(kind), {
25812580
getChangeRequestSummary: (input) =>
25822581
Effect.sync(() => {
25832582
seen.push({ cwd: input.cwd, repository: input.repository, host: input.host });
@@ -2619,7 +2618,7 @@ it.effect("prefers a matching checkout over a non-repository project's directory
26192618
project({ id: "repo", title: "API", workspaceRoot: "/api", repository: "acme/api" }),
26202619
],
26212620
providers: [
2622-
fakeProvider("github", {
2621+
fakeProvider(SourceControlProviderKind.make("github"), {
26232622
getChangeRequestSummary: (input) =>
26242623
Effect.sync(() => {
26252624
seen.push(input.cwd);
@@ -2645,7 +2644,7 @@ it.effect("requires an explicit host for a non-repository project's linked PR",
26452644
Effect.gen(function* () {
26462645
const service = yield* makeService({
26472646
projects: [project({ id: "inbox", title: "Inbox", workspaceRoot: "/home/alex" })],
2648-
providers: [fakeProvider("github")],
2647+
providers: [fakeProvider(SourceControlProviderKind.make("github"))],
26492648
});
26502649
const error = yield* service
26512650
.summary(
@@ -2663,7 +2662,10 @@ it.effect("requires an explicit host for a non-repository project's linked PR",
26632662

26642663
it.effect("refuses a public host reference without a selected project directory", () =>
26652664
Effect.gen(function* () {
2666-
const service = yield* makeService({ projects: [], providers: [fakeProvider("github")] });
2665+
const service = yield* makeService({
2666+
projects: [],
2667+
providers: [fakeProvider(SourceControlProviderKind.make("github"))],
2668+
});
26672669
const error = yield* service
26682670
.summary(
26692671
{
@@ -2679,6 +2681,29 @@ it.effect("refuses a public host reference without a selected project directory"
26792681
}),
26802682
);
26812683

2684+
it.effect(
2685+
"requires a checkout for GitLab because its adapter does not explicitly target the host",
2686+
() =>
2687+
Effect.gen(function* () {
2688+
const service = yield* makeService({
2689+
projects: [project({ id: "inbox", title: "Inbox", workspaceRoot: "/home/alex" })],
2690+
providers: [fakeProvider(SourceControlProviderKind.make("gitlab"))],
2691+
});
2692+
const error = yield* service
2693+
.summary(
2694+
{
2695+
projectId: "inbox" as ProjectId,
2696+
host: "gitlab.com",
2697+
repository: "acme/api",
2698+
number: 7,
2699+
},
2700+
{ recoverTransientFailure: false },
2701+
)
2702+
.pipe(Effect.flip);
2703+
assert.strictEqual(error._tag, "PullRequestUnavailableError");
2704+
}),
2705+
);
2706+
26822707
it.effect("refuses a hosted reference when its provider is unavailable", () =>
26832708
Effect.gen(function* () {
26842709
const service = yield* makeService({

‎apps/server/src/pullRequest/PullRequestService.ts‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,9 @@ export const make = Effect.gen(function* () {
902902
* The project whose checkout and credentials serve a reference. The project's own
903903
* repository is the default; a reference that names a `host` may instead point at any
904904
* repository on that host. Prefer its own checkout; providers with explicit repository
905-
* targeting can fall back to another checkout on the host. Public hosts can also use the
906-
* selected project's directory without a checkout. Azure derives its organization from
907-
* the checkout, so it requires a matching repository.
905+
* targeting can fall back to another checkout on the host. Providers with explicit host
906+
* targeting can also use the selected project's directory for supported public hosts.
907+
* Azure derives its organization from the checkout, so it requires a matching repository.
908908
*/
909909
const requireProject = (ref: PullRequestRef): Effect.Effect<SupportedProject, PullRequestError> =>
910910
listWorkspaceProjects({ projectId: ref.projectId }).pipe(
@@ -953,12 +953,8 @@ export const make = Effect.gen(function* () {
953953
return Effect.gen(function* () {
954954
// These providers target the repository explicitly and authenticate by host;
955955
// a linked PR in a non-repository project still needs its snapshot refreshed.
956-
const provider = [
957-
"github.com",
958-
"gitlab.com",
959-
"bitbucket.org",
960-
"codeberg.org",
961-
].includes(host)
956+
// GitLab still selects its host from the checkout or CLI configuration.
957+
const provider = ["github.com", "bitbucket.org", "codeberg.org"].includes(host)
962958
? detectSourceControlProviderFromRemoteUrl(`https://${host}/${repository}.git`)
963959
: null;
964960
const api = provider === null ? null : registry.get(provider.kind);
@@ -981,6 +977,7 @@ export const make = Effect.gen(function* () {
981977
repository,
982978
host,
983979
remote: normalizeGitRemoteUrl(`https://${host}/${repository}`),
980+
repositoryKey: null,
984981
};
985982
}
986983
}

0 commit comments

Comments
 (0)