Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions apps/server/src/issue/IssueService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,22 @@ describe("IssueService", () => {
projectId: "plain",
host: "gitea.test",
});
expect(
yield* ported.resolveUrl("https://gitea.test:9443/acme/web/issues/3").pipe(Effect.result),
).toMatchObject({
_tag: "Failure",
failure: { _tag: "IssueUnavailableError", reason: "tracker-unsupported" },
});
// GitLab bindings drop the remote's port, so a ported link still finds its hostname's project.
const gitlab = yield* makeService({
projects: [
project({ id: "gl", repository: "acme/web", provider: "gitlab", host: "gitlab.corp" }),
],
trackers: [fakeTracker({ kind: IssueTrackerKind.make("gitlab") })],
});
expect(
yield* gitlab.resolveUrl("https://gitlab.corp:8443/acme/web/-/issues/3"),
).toMatchObject({ projectId: "gl", host: "gitlab.corp", key: "3", writable: true });

// A GitHub Enterprise Server's hostname need not say "github"; its project vouches for it.
const enterprise = yield* makeService({
Expand Down
8 changes: 6 additions & 2 deletions apps/server/src/issue/IssueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -716,11 +716,15 @@ const make = Effect.gen(function* () {
}
const { tracker, link } = parsed;
// A link names its server's port; a binding does only when its remote or web URL did.
const authority = new URL(url).host.toLowerCase();
const parsedUrl = new URL(url);
const authority = parsedUrl.host.toLowerCase();
const { supported } = yield* listProjects({ host: link.host, authority });
const onHost = supported.filter((project) => project.tracker === tracker);
const onAuthority = onHost.filter((project) => project.host === authority);
const onTracker = onAuthority.length > 0 ? onAuthority : onHost;
// Only a host with its own `changeRequestHost` keeps ports, so only its ported links are exact.
const portIsExact =
parsedUrl.port !== "" && gitHost?.definition.changeRequestHost !== undefined;
const onTracker = onAuthority.length > 0 || portIsExact ? onAuthority : onHost;
const preferFirst = (projects: ReadonlyArray<SupportedProject>) =>
projects.find((project) => project.project.id === preferredProjectId) ?? projects[0];
const scope = link.scope.toLowerCase();
Expand Down
Loading