The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { gitLabReferenceAutolinks } from "./referenceAutolinks.ts"; |
| 4 | |
| 5 | const repositoryUrl = "https://gitlab.com/team/apps/web"; |
| 6 | const linked = (text: string) => |
| 7 | gitLabReferenceAutolinks(text, repositoryUrl).map(({ label, url, kind }) => [label, url, kind]); |
| 8 | |
| 9 | describe("gitLabReferenceAutolinks", () => { |
| 10 | it("links issues, merge requests, cross-project references, commits and mentions", () => { |
| 11 | expect( |
| 12 | linked( |
| 13 | "Closes #123 and !45, see api!9, other/group/lib#2; @julius.dev @team/mobile abc1234 api@abcdef1 GL-7 [issue:8] [issue:api/9] [issue:other/lib/3]", |
| 14 | ), |
| 15 | ).toEqual([ |
| 16 | ["#123", "https://gitlab.com/team/apps/web/-/issues/123", "reference"], |
| 17 | ["!45", "https://gitlab.com/team/apps/web/-/merge_requests/45", "reference"], |
| 18 | ["api!9", "https://gitlab.com/team/apps/api/-/merge_requests/9", "reference"], |
| 19 | ["other/group/lib#2", "https://gitlab.com/other/group/lib/-/issues/2", "reference"], |
| 20 | ["@julius.dev", "https://gitlab.com/julius.dev", "mention"], |
| 21 | ["@team/mobile", "https://gitlab.com/team/mobile", "mention"], |
| 22 | ["abc1234", "https://gitlab.com/team/apps/web/-/commit/abc1234", "commit"], |
| 23 | ["api@abcdef1", "https://gitlab.com/team/apps/api/-/commit/abcdef1", "commit"], |
| 24 | ["GL-7", "https://gitlab.com/team/apps/web/-/issues/7", "reference"], |
| 25 | ["[issue:8]", "https://gitlab.com/team/apps/web/-/issues/8", "reference"], |
| 26 | ["[issue:api/9]", "https://gitlab.com/team/apps/api/-/issues/9", "reference"], |
| 27 | ["[issue:other/lib/3]", "https://gitlab.com/other/lib/-/issues/3", "reference"], |
| 28 | ]); |
| 29 | }); |
| 30 | |
| 31 | it("shows a full SHA by its first seven characters", () => { |
| 32 | const sha = "0123456789abcdef0123456789abcdef01234567"; |
| 33 | expect(linked(`Reverts ${sha}.`)).toEqual([ |
| 34 | ["0123456", `https://gitlab.com/team/apps/web/-/commit/${sha}`, "commit"], |
| 35 | ]); |
| 36 | }); |
| 37 | |
| 38 | it("leaves URLs, escapes, emails, words, plain numbers and @all alone", () => { |
| 39 | expect( |
| 40 | linked( |
| 41 | "https://gitlab.com/a/b/-/issues/1#note_2 user@example.com \\!12 1234567 issue#x a!1b @all gl-4 XGL-5", |
| 42 | ), |
| 43 | ).toEqual([]); |
| 44 | }); |
| 45 | |
| 46 | it("scans long runs of periods, dashes and slashes in linear time", () => { |
| 47 | expect(linked(`${".".repeat(50_000)} ${".-/".repeat(25_000)} !1`)).toEqual([ |
| 48 | ["!1", "https://gitlab.com/team/apps/web/-/merge_requests/1", "reference"], |
| 49 | ]); |
| 50 | }); |
| 51 | |
| 52 | it("links references that follow punctuation and a mention's trailing period", () => { |
| 53 | expect(linked("(!5), thanks @julius.")).toEqual([ |
| 54 | ["!5", "https://gitlab.com/team/apps/web/-/merge_requests/5", "reference"], |
| 55 | ["@julius", "https://gitlab.com/julius", "mention"], |
| 56 | ]); |
| 57 | }); |
| 58 | |
| 59 | it("links against the repository's own host", () => { |
| 60 | expect( |
| 61 | gitLabReferenceAutolinks("See !5", "https://git.example.com/acme/web").map(({ url }) => url), |
| 62 | ).toEqual(["https://git.example.com/acme/web/-/merge_requests/5"]); |
| 63 | }); |
| 64 | }); |