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
13 changes: 13 additions & 0 deletions packages/client-runtime/src/promptLinks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ describe("findPromptLinkProjects", () => {
expect(ids("me", "t3code")).toEqual(["fork"]);
expect(ids("gitlab", "x")).toEqual([]);
});

it("matches a checkout of the repository's GitCafe mirror", () => {
const projects = [
{ id: "gitcafe", repositoryIdentity: identity("git.cafe/pingdotgg/t3code") },
{ id: "staging", repositoryIdentity: identity("staging.git.cafe/pingdotgg/t3code") },
{ id: "gitlab", repositoryIdentity: identity("gitlab.com/pingdotgg/t3code") },
];
expect(
findPromptLinkProjects(projects, { owner: "pingdotgg", name: "t3code" }).map(
(project) => project.id,
),
).toEqual(["gitcafe", "staging"]);
});
});

describe("pickPromptLinkPullRequestThread", () => {
Expand Down
10 changes: 6 additions & 4 deletions packages/client-runtime/src/promptLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import {
visibleThreadPullRequests,
} from "./threadPullRequests.ts";

const repositoryKey = (repository: PromptLinkRepository) =>
`github.com/${repository.owner}/${repository.name}`.toLowerCase();
// A link's `owner/name` is GitHub's. GitCafe syncs a repository two-way with GitHub under the
// same path, so a checkout cloned from git.cafe counts as the linked repository.
const PROMPT_LINK_REPOSITORY_HOSTS = ["github.com", "git.cafe", "staging.git.cafe"];

/**
* The repository's projects in the order given. Callers pass projects most recently active
Expand All @@ -28,11 +29,12 @@ const repositoryKey = (repository: PromptLinkRepository) =>
export function findPromptLinkProjects<
P extends { readonly repositoryIdentity?: RepositoryIdentity | null | undefined },
>(projects: ReadonlyArray<P>, repository: PromptLinkRepository): P[] {
const key = repositoryKey(repository);
const path = `${repository.owner}/${repository.name}`.toLowerCase();
const keys = new Set(PROMPT_LINK_REPOSITORY_HOSTS.map((host) => `${host}/${path}`));
return projects.filter(
(project) =>
project.repositoryIdentity != null &&
repositoryGroupingKeyOf(project.repositoryIdentity).toLowerCase() === key,
keys.has(repositoryGroupingKeyOf(project.repositoryIdentity).toLowerCase()),
);
}

Expand Down
Loading