Open History to see the last commit
1import { recognizeRemoteWith } from "@t3tools/source-control-core/shared/definition";
2import { describe, expect, it } from "vite-plus/test";
3
4import { definition } from "./definition.ts";
5
6const parse = (url: string) => definition.parseChangeRequestUrl(new URL(url));
7
8describe("GitLab change request URLs", () => {
9 it("reads a merge request on any host, nested groups and all", () => {
10 expect(parse("https://gitlab.com/t3tools/platform/t3code/-/merge_requests/42")).toEqual({
11 host: "gitlab.com",
12 repository: "t3tools/platform/t3code",
13 number: 42,
14 repositoryUrl: "https://gitlab.com/t3tools/platform/t3code",
15 });
16 expect(parse("https://code.acme.test/team/project/-/merge_requests/9")).toMatchObject({
17 host: "code.acme.test",
18 repository: "team/project",
19 number: 9,
20 });
21 });
22
23 it("keeps pull-like segments inside nested repository paths", () => {
24 expect(
25 parse("https://gitlab.example.test/group/pull/123/repo/-/merge_requests/42")?.repositoryUrl,
26 ).toBe("https://gitlab.example.test/group/pull/123/repo");
27 });
28
29 it("leaves issues and single-segment paths alone", () => {
30 expect(parse("https://gitlab.com/t3tools/t3code/-/issues/12")).toBeNull();
31 expect(parse("https://gitlab.com/t3code/-/merge_requests/12")).toBeNull();
32 });
33
34 it("builds merge request URLs below the repository", () => {
35 expect(
36 definition.changeRequestUrl({
37 host: "gitlab.com",
38 repository: "group/sub/project",
39 number: 4,
40 }),
41 ).toBe("https://gitlab.com/group/sub/project/-/merge_requests/4");
42 expect(
43 definition.changeRequestUrl({
44 host: "gitlab.com",
45 repository: "group/sub/project",
46 number: 4,
47 webUrl: "https://gitlab.com/group/sub/project",
48 }),
49 ).toBe("https://gitlab.com/group/sub/project/-/merge_requests/4");
50 });
51});
52
53describe("GitLab remotes", () => {
54 const recognize = (url: string) => recognizeRemoteWith(definition, url);
55
56 it("keeps an HTTP port in the base URL and drops an SSH one", () => {
57 expect(recognize("https://gitlab.com:8443/group/repo.git")).toEqual({
58 kind: "gitlab",
59 name: "GitLab",
60 baseUrl: "https://gitlab.com:8443",
61 });
62 expect(recognize("ssh://git@gitlab.example.test:24/group/repo.git")).toEqual({
63 kind: "gitlab",
64 name: "GitLab Self-Hosted",
65 baseUrl: "https://gitlab.example.test",
66 });
67 expect(recognize("gitlab@gitlab.example.com:group/project.git")?.baseUrl).toBe(
68 "https://gitlab.example.com",
69 );
70 });
71
72 it("matches complete DNS labels only", () => {
73 expect(recognize("https://notgitlab.example.com/group/repo.git")).toBeNull();
74 });
75});