diff --git a/packages/opencode/src/cli/cmd/github.ts b/packages/opencode/src/cli/cmd/github.ts index c44b58d6a4..898b733128 100644 --- a/packages/opencode/src/cli/cmd/github.ts +++ b/packages/opencode/src/cli/cmd/github.ts @@ -33,7 +33,7 @@ import { AppRuntime } from "@/effect/app-runtime" import { Git } from "@/git" import { setTimeout as sleep } from "node:timers/promises" import { Process } from "@/util" -import { parseGitHubRemote } from "@/util/github-remote" +import { parseGitHubRemote } from "@/util/repository" import { Effect } from "effect" type GitHubAuthor = { diff --git a/packages/opencode/src/util/github-remote.ts b/packages/opencode/src/util/github-remote.ts deleted file mode 100644 index fc30e2cfcf..0000000000 --- a/packages/opencode/src/util/github-remote.ts +++ /dev/null @@ -1,34 +0,0 @@ -function normalize(input: string) { - return input.trim().replace(/^git\+/, "").replace(/#.*$/, "") -} - -export function parseGitHubRemote(url: string): { owner: string; repo: string } | null { - const match = normalize(url).match(/^(?:(?:https?|ssh|git):\/\/)?(?:git@)?github\.com[:/]([^/]+)\/([^/]+?)(?:\.git)?$/) - if (!match) return null - return { owner: match[1], repo: match[2] } -} - -export function parseGitHubRepository(input: string): { owner: string; repo: string } | null { - const cleaned = normalize(input) - const remote = parseGitHubRemote(cleaned) - if (remote) return remote - - const prefixed = cleaned.match(/^github:([^/\s]+)\/([^/\s]+)$/) - if (prefixed) { - return { owner: prefixed[1], repo: prefixed[2].replace(/\.git$/, "") } - } - - const match = cleaned.match(/^([^/\s]+)\/([^/\s]+)$/) - if (!match) return null - return { owner: match[1], repo: match[2].replace(/\.git$/, "") } -} - -export function githubRepositoryURL(input: { owner: string; repo: string }) { - return `https://github.com/${input.owner}/${input.repo}` -} - -export function githubCloneURL(input: { owner: string; repo: string }) { - const base = process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL - if (!base) return `https://github.com/${input.owner}/${input.repo}.git` - return new URL(`${input.owner}/${input.repo}.git`, base.endsWith("/") ? base : `${base}/`).href -} diff --git a/packages/opencode/src/util/repository.ts b/packages/opencode/src/util/repository.ts index f9ffb0e49c..30c680b4ee 100644 --- a/packages/opencode/src/util/repository.ts +++ b/packages/opencode/src/util/repository.ts @@ -88,6 +88,15 @@ export function parseRepositoryReference(input: string) { } } +export function parseGitHubRemote(input: string) { + const cleaned = normalize(input) + if (!cleaned.includes("://") && !cleaned.match(/^(?:[^@/\s]+@)?github\.com:/)) return null + + const parsed = parseRepositoryReference(cleaned) + if (!parsed || parsed.host !== "github.com" || !parsed.owner || parsed.segments.length !== 2) return null + return { owner: parsed.owner, repo: parsed.repo } +} + export function repositoryCachePath(input: Reference) { return path.join(Global.Path.repos, ...input.host.split(":"), ...input.segments) }