Skip to content
Merged
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
11 changes: 11 additions & 0 deletions packages/client-runtime/src/issueLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ describe("resolveIssueLinkTarget", () => {
expect(target?.ref).toMatchObject({ projectId: "fork", scope: "me/web", key: "3" });
});

it("uses the current repository identity after a project changes repositories", () => {
const url = "https://github.com/acme/api/issues/7";
const original = project("p1", "acme/api");
const replacement = project("p1", "acme/mobile");
const lender = project("p3", "acme/web");
expect(resolveIssueLinkTarget({ url, projects: [lender, original] })?.ref.projectId).toBe("p1");
expect(resolveIssueLinkTarget({ url, projects: [lender, replacement] })?.ref.projectId).toBe(
"p3",
);
});

it("prefers the project bound to the link's own port over one on the bare hostname", () => {
const enterprise = (id: string, host: string) =>
({
Expand Down
16 changes: 14 additions & 2 deletions packages/client-runtime/src/issueLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
issueTrackerBindingScopes,
type IssueRef,
type IssueTrackerConnectionList,
type RepositoryIdentity,
} from "@t3tools/contracts";
import {
LINEAR_HOST,
Expand All @@ -15,11 +16,22 @@ import type { EnvironmentProject } from "./state/shell.ts";

type LinkProject = Pick<EnvironmentProject, "id" | "environmentId" | "repositoryIdentity">;

const issueBindingsByRepository = new WeakMap<
RepositoryIdentity,
ReturnType<typeof sourceControlClients.issueBindings>
>();

/** The hosts and scopes a project's git-host tracker is bound to, the way the server resolves them. */
function projectIssueBindings(project: LinkProject) {
return sourceControlClients
.issueBindings(project.repositoryIdentity)
const identity = project.repositoryIdentity;
if (identity == null) return [];
const cached = issueBindingsByRepository.get(identity);
if (cached !== undefined) return cached;
const bindings = sourceControlClients
.issueBindings(identity)
.map((binding) => ({ ...binding, scope: binding.scope.toLowerCase() }));
issueBindingsByRepository.set(identity, bindings);
return bindings;
}

function linkAuthority(url: string): string | null {
Expand Down
Loading