Open History to see the last commit
1import { expect, it } from "@effect/vitest";
2
3import {
4 BUILT_IN_SOURCE_CONTROL_DRIVER_LIST,
5 changeRequestsClosedBy,
6 sourceControlDefinitions,
7} from "./sourceControlDefinitions.ts";
8
9it("runs a driver for every host the server and clients read, in their order", () => {
10 expect(BUILT_IN_SOURCE_CONTROL_DRIVER_LIST.map((driver) => driver.definition)).toEqual(
11 sourceControlDefinitions.definitions,
12 );
13});
14
15it.each([
16 "C:/repos/project",
17 "C:\\repos\\project",
18 "/srv/git/repo.git",
19 "./team:group/repo",
20 "file:///srv/git/repo.git",
21 "hg::team/repo",
22 "codecommit::us-east-1://repo",
23])("finds no host in %s, which git does not read as SSH", (remoteUrl) => {
24 expect(sourceControlDefinitions.recognizeRemote(remoteUrl)).toBeNull();
25});
26
27it.each([
28 ["https://github.com/Acme/Web/issues/42", "github", "github.com", "acme/web", "42"],
29 [
30 "https://gitlab.acme.test/group/sub/web/-/issues/7",
31 "gitlab",
32 "gitlab.acme.test",
33 "group/sub/web",
34 "7",
35 ],
36 ["https://gitlab.com/acme/web/-/issues/incident/12", "gitlab", "gitlab.com", "acme/web", "12"],
37 ["https://codeberg.org/acme/web/issues/3", "forgejo", "codeberg.org", "acme/web", "3"],
38 [
39 "https://dev.azure.com/acme/Web%20App/_workitems/edit/9",
40 "azure-devops",
41 "dev.azure.com",
42 "acme/web app",
43 "9",
44 ],
45] as const)("reads %s as an issue on its host", (url, kind, host, scope, key) => {
46 const parsed = sourceControlDefinitions.parseIssueUrl(url);
47 expect(parsed?.definition.kind).toBe(kind);
48 expect(parsed?.link).toEqual({ host, scope, key });
49});
50
51it.each([
52 "https://github.com/acme/web/pull/42",
53 "https://example.test/acme/web/issues/42",
54 "https://github.com/acme/web/issues/0",
55 "https://gitlab.com/groups/acme/-/work_items/12",
56])("does not read %s as an issue", (url) => {
57 expect(sourceControlDefinitions.parseIssueUrl(url)).toBeNull();
58});
59
60it.each([
61 ["gh pr merge 19 --squash", [19]],
62 ['gh pr merge "19" --squash', [19]],
63 ['/bin/zsh -lc "gh pr merge 19"', [19]],
64 ['/bin/zsh -lc "gh pr merge 19" > "merge.log"', [19]],
65 [`/bin/zsh -lc 'gh pr merge 19' > 'merge.log'`, [19]],
66 ['gh pr merge 19 --squash --subject "Release 20"', [19]],
67 [`/bin/zsh -lc "gh pr merge 19 --subject 'Release 20'"`, [19]],
68 ["gh pr merge 19 --body 'see https://github.com/o/r/pull/20'", [19]],
69 ["gh pr merge 19 --body https://github.com/o/r/pull/20", [19]],
70 ["gh pr merge 19 # then 20", [19]],
71 ["gh pr merge --squash --match-head-commit 3b2f958 #19", [19]],
72 ["gh pr merge --squash --subject=2026 42", [42]],
73 ['gh pr merge --squash --subject="2026" 42', [42]],
74 ["gh pr merge --body=https://github.com/o/r/pull/20 19", [19]],
75 ["gh pr close https://github.com/o/r/pull/19 && gh pr merge 20", [19, 20]],
76 ["glab mr merge https://gitlab.com/o/r/-/merge_requests/7", [7]],
77 ["sleep 30; cafe pr merge 26271", [26271]],
78 ["az repos pr update --id 19 --status completed", [19]],
79 ["az repos pr update --id=19 --status=abandoned", [19]],
80 ['az repos pr update --id="19" --title "20" --status completed', [19]],
81 ["gh pr merge --squash", "any"],
82 ["gh stack merge", "any"],
83 ["gh pr merge 19 && gh pr merge --auto", "any"],
84] as const)("%s closes %j", (command, expected) => {
85 const closed = changeRequestsClosedBy(command);
86 expect(closed === "any" ? closed : [...closed]).toEqual(expected);
87});