@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 90 lines 3.2 KB
Raw
1 import { recognizeRemoteWith } from "@t3tools/source-control-core/shared/definition";
2 import { describe, expect, it } from "vite-plus/test";
3
4 import { definition } from "./definition.ts";
5
6 const parse = (url: string) => definition.parseChangeRequestUrl(new URL(url));
7
8 describe("Bitbucket change request URLs", () => {
9 it("reads a pull request on Bitbucket hosts", () => {
10 expect(
11 definition.isChangeRequestReference(
12 "https://bitbucket.org/workspace/repo/pull-requests/5/diff",
13 ),
14 ).toBe(true);
15 expect(parse("https://bitbucket.org/workspace/repo/pull-requests/5/diff")).toEqual({
16 host: "bitbucket.org",
17 repository: "workspace/repo",
18 number: 5,
19 repositoryUrl: "https://bitbucket.org/workspace/repo",
20 });
21 expect(parse("https://code.bitbucket.example.test/team/repo/pull-requests/6")).toMatchObject({
22 host: "code.bitbucket.example.test",
23 number: 6,
24 });
25 });
26
27 it("leaves other hosts alone", () => {
28 expect(parse("https://scm.example.test/workspace/repo/pull-requests/5")).toBeNull();
29 expect(
30 definition.isChangeRequestReference(
31 "https://scm.example.test/workspace/repo/pull-requests/5",
32 ),
33 ).toBe(false);
34 expect(
35 definition.isChangeRequestReference("https://bitbucket.org/workspace/repo/src/main"),
36 ).toBe(false);
37 });
38
39 it("builds pull request URLs below the repository", () => {
40 expect(
41 definition.changeRequestUrl({ host: "bitbucket.org", repository: "w/repo", number: 5 }),
42 ).toBe("https://bitbucket.org/w/repo/pull-requests/5");
43 expect(
44 definition.changeRequestUrl({
45 host: "bitbucket.org",
46 repository: "w/repo",
47 number: 5,
48 webUrl: "https://bitbucket.org/w/repo",
49 }),
50 ).toBe("https://bitbucket.org/w/repo/pull-requests/5");
51 });
52 });
53
54 describe("Bitbucket repository pages", () => {
55 it("reads the repository from a source view on Bitbucket hosts only", () => {
56 const repositoryUrl = (url: string) => definition.repositoryUrlFromPage?.(new URL(url));
57 expect(repositoryUrl("https://bitbucket.org/workspace/repo/src/main/")).toBe(
58 "https://bitbucket.org/workspace/repo",
59 );
60 expect(repositoryUrl("https://bitbucket.org/workspace/repo")).toBeNull();
61 expect(repositoryUrl("https://scm.example.test/workspace/repo/src/main/")).toBeNull();
62 });
63 });
64
65 describe("Bitbucket remotes", () => {
66 const recognize = (url: string) => recognizeRemoteWith(definition, url);
67
68 it("recognises bitbucket.org and hosts with a bitbucket label", () => {
69 expect(recognize("git@bitbucket.org:workspace/repo.git")).toEqual({
70 kind: "bitbucket",
71 name: "Bitbucket",
72 baseUrl: "https://bitbucket.org",
73 });
74 expect(recognize("https://bitbucket.example.com/workspace/repo.git")?.name).toBe(
75 "Bitbucket Self-Hosted",
76 );
77 expect(recognize("https://notbitbucket.example.com/workspace/repo.git")).toBeNull();
78 });
79
80 it.each([
81 "git@ssh.bitbucket.org:workspace/repo.git",
82 "ssh://git@altssh.bitbucket.org:443/workspace/repo.git",
83 ])("recognises Bitbucket Cloud's SSH host in %s", (url) => {
84 expect(recognize(url)).toEqual({
85 kind: "bitbucket",
86 name: "Bitbucket",
87 baseUrl: "https://bitbucket.org",
88 });
89 });
90 });