github-remote.test.ts 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { test, expect } from "bun:test"
  2. import { parseGitHubRemote } from "../../src/cli/cmd/github"
  3. test("parses https URL with .git suffix", () => {
  4. expect(parseGitHubRemote("https://github.com/sst/opencode.git")).toEqual({ owner: "sst", repo: "opencode" })
  5. })
  6. test("parses https URL without .git suffix", () => {
  7. expect(parseGitHubRemote("https://github.com/sst/opencode")).toEqual({ owner: "sst", repo: "opencode" })
  8. })
  9. test("parses git@ URL with .git suffix", () => {
  10. expect(parseGitHubRemote("[email protected]:sst/opencode.git")).toEqual({ owner: "sst", repo: "opencode" })
  11. })
  12. test("parses git@ URL without .git suffix", () => {
  13. expect(parseGitHubRemote("[email protected]:sst/opencode")).toEqual({ owner: "sst", repo: "opencode" })
  14. })
  15. test("parses ssh:// URL with .git suffix", () => {
  16. expect(parseGitHubRemote("ssh://[email protected]/sst/opencode.git")).toEqual({ owner: "sst", repo: "opencode" })
  17. })
  18. test("parses ssh:// URL without .git suffix", () => {
  19. expect(parseGitHubRemote("ssh://[email protected]/sst/opencode")).toEqual({ owner: "sst", repo: "opencode" })
  20. })
  21. test("parses http URL", () => {
  22. expect(parseGitHubRemote("http://github.com/owner/repo")).toEqual({ owner: "owner", repo: "repo" })
  23. })
  24. test("parses URL with hyphenated owner and repo names", () => {
  25. expect(parseGitHubRemote("https://github.com/my-org/my-repo.git")).toEqual({ owner: "my-org", repo: "my-repo" })
  26. })
  27. test("parses URL with underscores in names", () => {
  28. expect(parseGitHubRemote("[email protected]:my_org/my_repo.git")).toEqual({ owner: "my_org", repo: "my_repo" })
  29. })
  30. test("parses URL with numbers in names", () => {
  31. expect(parseGitHubRemote("https://github.com/org123/repo456")).toEqual({ owner: "org123", repo: "repo456" })
  32. })
  33. test("parses repos with dots in the name", () => {
  34. expect(parseGitHubRemote("https://github.com/socketio/socket.io.git")).toEqual({
  35. owner: "socketio",
  36. repo: "socket.io",
  37. })
  38. expect(parseGitHubRemote("https://github.com/vuejs/vue.js")).toEqual({
  39. owner: "vuejs",
  40. repo: "vue.js",
  41. })
  42. expect(parseGitHubRemote("[email protected]:mrdoob/three.js.git")).toEqual({
  43. owner: "mrdoob",
  44. repo: "three.js",
  45. })
  46. expect(parseGitHubRemote("https://github.com/jashkenas/backbone.git")).toEqual({
  47. owner: "jashkenas",
  48. repo: "backbone",
  49. })
  50. })
  51. test("returns null for non-github URLs", () => {
  52. expect(parseGitHubRemote("https://gitlab.com/owner/repo.git")).toBeNull()
  53. expect(parseGitHubRemote("[email protected]:owner/repo.git")).toBeNull()
  54. expect(parseGitHubRemote("https://bitbucket.org/owner/repo")).toBeNull()
  55. })
  56. test("returns null for invalid URLs", () => {
  57. expect(parseGitHubRemote("not-a-url")).toBeNull()
  58. expect(parseGitHubRemote("")).toBeNull()
  59. expect(parseGitHubRemote("github.com")).toBeNull()
  60. expect(parseGitHubRemote("https://github.com/")).toBeNull()
  61. expect(parseGitHubRemote("https://github.com/owner")).toBeNull()
  62. })
  63. test("returns null for URLs with extra path segments", () => {
  64. expect(parseGitHubRemote("https://github.com/owner/repo/tree/main")).toBeNull()
  65. expect(parseGitHubRemote("https://github.com/owner/repo/blob/main/file.ts")).toBeNull()
  66. })