Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import { parsePullRequestReference } from "./pullRequestReference";
4
5describe("parsePullRequestReference", () => {
6 it("accepts GitHub pull request URLs", () => {
7 expect(parsePullRequestReference("https://github.com/pingdotgg/pikucode/pull/42")).toBe(
8 "https://github.com/pingdotgg/pikucode/pull/42",
9 );
10 });
11
12 it("accepts Azure DevOps pull request URLs", () => {
13 expect(
14 parsePullRequestReference("https://dev.azure.com/acme/project/_git/pikucode/pullrequest/42"),
15 ).toBe("https://dev.azure.com/acme/project/_git/pikucode/pullrequest/42");
16 });
17
18 it("accepts GitLab merge request URLs", () => {
19 expect(parsePullRequestReference("https://gitlab.com/group/project/-/merge_requests/42")).toBe(
20 "https://gitlab.com/group/project/-/merge_requests/42",
21 );
22 });
23
24 it("accepts legacy Azure DevOps pull request URLs", () => {
25 expect(
26 parsePullRequestReference(
27 "https://acme.visualstudio.com/project/_git/pikucode/pullrequest/42",
28 ),
29 ).toBe("https://acme.visualstudio.com/project/_git/pikucode/pullrequest/42");
30 });
31
32 it("accepts raw numbers", () => {
33 expect(parsePullRequestReference("42")).toBe("42");
34 });
35
36 it("accepts #number references", () => {
37 expect(parsePullRequestReference("#42")).toBe("42");
38 });
39
40 it("accepts gh pr checkout commands with raw numbers", () => {
41 expect(parsePullRequestReference("gh pr checkout 42")).toBe("42");
42 });
43
44 it("accepts gh pr checkout commands with #number references", () => {
45 expect(parsePullRequestReference("gh pr checkout #42")).toBe("42");
46 });
47
48 it("accepts gh pr checkout commands with GitHub pull request URLs", () => {
49 expect(
50 parsePullRequestReference("gh pr checkout https://github.com/pingdotgg/pikucode/pull/42"),
51 ).toBe("https://github.com/pingdotgg/pikucode/pull/42");
52 });
53
54 it("accepts glab mr checkout commands with raw numbers", () => {
55 expect(parsePullRequestReference("glab mr checkout 42")).toBe("42");
56 });
57
58 it("accepts az repos pr checkout commands with raw numbers", () => {
59 expect(parsePullRequestReference("az repos pr checkout --id 42")).toBe("42");
60 });
61
62 it("accepts az repos pr checkout commands with equals-style ids", () => {
63 expect(parsePullRequestReference("az repos pr checkout --id=42")).toBe("42");
64 });
65
66 it("accepts az repos pr checkout commands with extra flags", () => {
67 expect(parsePullRequestReference("az repos pr checkout --id 42 --remote-name origin")).toBe(
68 "42",
69 );
70 });
71
72 it("rejects non-pull-request input", () => {
73 expect(parsePullRequestReference("feature/my-branch")).toBeNull();
74 });
75});