Open History to see the last commit
1import { EnvironmentId, ProjectId, SourceControlProviderKind } from "@t3tools/contracts";
2import { describe, expect, it } from "vite-plus/test";
3import { nativePullRequestDestination } from "../../lib/pullRequestNavigation";
4
5const context = { environmentId: "remote", projectId: "project" };
6const project = (id: string, canonicalKey: string, provider: string, remoteUrl: string) => ({
7 id: ProjectId.make(id),
8 environmentId: EnvironmentId.make("remote"),
9 repositoryIdentity: {
10 canonicalKey,
11 locator: { source: "git-remote" as const, remoteName: "origin", remoteUrl },
12 displayName: canonicalKey.split("/").slice(1).join("/"),
13 provider: SourceControlProviderKind.make(provider),
14 },
15});
16const projects = [
17 project("project", "github.com/org/repo", "github", "git@github.com:org/repo.git"),
18 project("gitlab", "git.example/group/sub/repo", "gitlab", "git@git.example:group/sub/repo.git"),
19 project("forgejo", "forgejo.test/org/repo", "forgejo", "http://forgejo.test:3000/org/repo.git"),
20];
21
22describe("native PR entry points", () => {
23 it("keeps a thread link in its own environment and handles renamed host path shapes", () => {
24 expect(
25 nativePullRequestDestination(
26 "https://github.com/org/repo/pull/12/files#diff",
27 context,
28 projects,
29 ),
30 ).toEqual({ ...context, host: "github.com", repository: "org/repo", number: 12 });
31 expect(
32 nativePullRequestDestination(
33 "https://git.example/group/sub/repo/-/merge_requests/9",
34 context,
35 projects,
36 ),
37 ).toMatchObject({ projectId: "gitlab", repository: "group/sub/repo" });
38 expect(
39 nativePullRequestDestination("http://forgejo.test:3000/org/repo/pulls/3", context, projects)
40 ?.host,
41 ).toBe("forgejo.test:3000");
42 });
43
44 it("leaves pull requests from repositories without a project to the external opener", () => {
45 expect(
46 nativePullRequestDestination("https://github.com/someone/else/pull/12", context, projects),
47 ).toBeNull();
48 });
49
50 it("leaves issues, unknown sites, and unscoped links to the external opener", () => {
51 expect(
52 nativePullRequestDestination("https://github.com/org/repo/issues/12", context, projects),
53 ).toBeNull();
54 expect(
55 nativePullRequestDestination("https://example.com/org/repo/pull/12", context, projects),
56 ).toBeNull();
57 expect(
58 nativePullRequestDestination("https://github.com/org/repo/pull/12", null, projects),
59 ).toBeNull();
60 });
61});