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