Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions packages/cli/src/__tests__/github.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { describe, expect, it } from "vitest";
import { isGitHubRemote, parseGitHubRepo } from "../github/index.js";

describe("parseGitHubRepo", () => {
it("parses the SSH shorthand form", () => {
expect(parseGitHubRepo("git@github.com:owner/repo.git")).toEqual({
owner: "owner",
repo: "repo",
});
});

it("parses the HTTPS form", () => {
expect(parseGitHubRepo("https://github.com/owner/repo.git")).toEqual({
owner: "owner",
repo: "repo",
});
});

it("parses the ssh:// URL form without a .git suffix", () => {
expect(parseGitHubRepo("ssh://git@github.com/acme/Stage-CLI")).toEqual({
owner: "acme",
repo: "Stage-CLI",
});
});

it("returns null for non-GitHub hosts", () => {
expect(parseGitHubRepo("git@gitlab.com:owner/repo.git")).toBeNull();
expect(parseGitHubRepo("https://bitbucket.org/owner/repo.git")).toBeNull();
});

it("returns null for look-alike hosts that merely contain github.com", () => {
expect(parseGitHubRepo("https://notgithub.com.evil.test/owner/repo")).toBeNull();
});

it("returns null when no origin is configured", () => {
expect(parseGitHubRepo(null)).toBeNull();
});
});

describe("isGitHubRemote", () => {
it("is true for github.com remotes", () => {
expect(isGitHubRemote("git@github.com:owner/repo.git")).toBe(true);
});

it("is false for non-GitHub and missing remotes", () => {
expect(isGitHubRemote("git@gitlab.com:owner/repo.git")).toBe(false);
expect(isGitHubRemote(null)).toBe(false);
});
});
Loading
Loading