| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- import { test, expect } from "bun:test"
- import { parseGitHubRemote } from "../../src/cli/cmd/github"
- test("parses https URL with .git suffix", () => {
- expect(parseGitHubRemote("https://github.com/sst/opencode.git")).toEqual({ owner: "sst", repo: "kirincode" })
- })
- test("parses https URL without .git suffix", () => {
- expect(parseGitHubRemote("https://github.com/sst/opencode")).toEqual({ owner: "sst", repo: "kirincode" })
- })
- test("parses git@ URL with .git suffix", () => {
- expect(parseGitHubRemote("git@github.com:sst/opencode.git")).toEqual({ owner: "sst", repo: "kirincode" })
- })
- test("parses git@ URL without .git suffix", () => {
- expect(parseGitHubRemote("git@github.com:sst/opencode")).toEqual({ owner: "sst", repo: "kirincode" })
- })
- test("parses ssh:// URL with .git suffix", () => {
- expect(parseGitHubRemote("ssh://git@github.com/sst/opencode.git")).toEqual({ owner: "sst", repo: "kirincode" })
- })
- test("parses ssh:// URL without .git suffix", () => {
- expect(parseGitHubRemote("ssh://git@github.com/sst/opencode")).toEqual({ owner: "sst", repo: "kirincode" })
- })
- test("parses git protocol URLs from package metadata", () => {
- expect(parseGitHubRemote("git://github.com/facebook/react.git")).toEqual({ owner: "facebook", repo: "react" })
- expect(parseGitHubRemote("git+https://github.com/facebook/react.git")).toEqual({ owner: "facebook", repo: "react" })
- expect(parseGitHubRemote("git+ssh://git@github.com/facebook/react.git")).toEqual({ owner: "facebook", repo: "react" })
- })
- test("parses npm-style github shorthand", () => {
- expect(parseGitHubRemote("github:facebook/react")).toBeNull()
- })
- test("parses http URL", () => {
- expect(parseGitHubRemote("http://github.com/owner/repo")).toEqual({ owner: "owner", repo: "repo" })
- })
- test("parses URL with hyphenated owner and repo names", () => {
- expect(parseGitHubRemote("https://github.com/my-org/my-repo.git")).toEqual({ owner: "my-org", repo: "my-repo" })
- })
- test("parses URL with underscores in names", () => {
- expect(parseGitHubRemote("git@github.com:my_org/my_repo.git")).toEqual({ owner: "my_org", repo: "my_repo" })
- })
- test("parses URL with numbers in names", () => {
- expect(parseGitHubRemote("https://github.com/org123/repo456")).toEqual({ owner: "org123", repo: "repo456" })
- })
- test("parses repos with dots in the name", () => {
- expect(parseGitHubRemote("https://github.com/socketio/socket.io.git")).toEqual({
- owner: "socketio",
- repo: "socket.io",
- })
- expect(parseGitHubRemote("https://github.com/vuejs/vue.js")).toEqual({
- owner: "vuejs",
- repo: "vue.js",
- })
- expect(parseGitHubRemote("git@github.com:mrdoob/three.js.git")).toEqual({
- owner: "mrdoob",
- repo: "three.js",
- })
- expect(parseGitHubRemote("https://github.com/jashkenas/backbone.git")).toEqual({
- owner: "jashkenas",
- repo: "backbone",
- })
- })
- test("returns null for non-github URLs", () => {
- expect(parseGitHubRemote("https://gitlab.com/owner/repo.git")).toBeNull()
- expect(parseGitHubRemote("git@gitlab.com:owner/repo.git")).toBeNull()
- expect(parseGitHubRemote("https://bitbucket.org/owner/repo")).toBeNull()
- })
- test("returns null for invalid URLs", () => {
- expect(parseGitHubRemote("not-a-url")).toBeNull()
- expect(parseGitHubRemote("")).toBeNull()
- expect(parseGitHubRemote("github.com")).toBeNull()
- expect(parseGitHubRemote("https://github.com/")).toBeNull()
- expect(parseGitHubRemote("https://github.com/owner")).toBeNull()
- })
- test("returns null for URLs with extra path segments", () => {
- expect(parseGitHubRemote("https://github.com/owner/repo/tree/main")).toBeNull()
- expect(parseGitHubRemote("https://github.com/owner/repo/blob/main/file.ts")).toBeNull()
- })
|