Documentation
¶
Overview ¶
Package clonenext — github.go checks and creates GitHub repositories.
Index ¶
- Constants
- Variables
- func CreateRepo(owner, repoName string, private bool) error
- func HasGitSubdir(root string) bool
- func IsGitRepo(path string) bool
- func LoadBatchFromCSV(path string) ([]string, error)
- func ParseOwnerRepo(remoteURL string) (string, string, error)
- func ReplaceRepoInURL(remoteURL, currentRepo, targetRepo string) string
- func RepoExists(owner, repo string) (bool, error)
- func ResolveTarget(parsed ParsedRepo, arg string) (int, error)
- func TargetRepoName(baseName string, version int) string
- func WalkBatchFromDir(root string) ([]string, error)
- type LocalRepoState
- type ParsedRepo
- type RemoteUpdateCheck
Constants ¶
const DefaultRemoteProbeCeiling = 30
DefaultRemoteProbeCeiling caps how far above the current version we probe before giving up. Mirrors install.sh's PROBE_CEILING default.
Variables ¶
var ErrBatchEmpty = errors.New("clonenext: batch input contained no repos")
ErrBatchEmpty is returned when neither the CSV nor the cwd walk yielded any candidate repos. Callers surface this as a soft warning, not a crash.
var ErrNotAGitRepo = errors.New("clonenext: path is not a git repository")
ErrNotAGitRepo is returned when path has no .git entry.
Functions ¶
func CreateRepo ¶
CreateRepo creates a new GitHub repository under the given owner. It detects whether the owner is a user or organization and calls the appropriate endpoint. The repo is created as private by default.
func HasGitSubdir ¶
HasGitSubdir reports whether `root` contains at least one immediate child directory that is itself a git repo. Designed for the cn dispatcher's implicit-batch trigger: it short-circuits on the first hit, so the cost is bounded to one ReadDir + at most one Stat per candidate up to the first match. Returns false on any I/O error so the dispatcher fails closed (single-repo path → clean "no remote" error) rather than guessing.
func IsGitRepo ¶
IsGitRepo reports whether path contains a .git entry (file or directory — `.git` files exist for git worktrees). Exported so the cmd-package dispatcher can decide between single-repo and batch mode without importing internal helpers.
func LoadBatchFromCSV ¶
LoadBatchFromCSV reads a CSV file and returns one absolute repo path per non-empty data row. See the package doc-comment for the full parsing contract (BOM, line endings, header detection, optional columns).
func ParseOwnerRepo ¶
ParseOwnerRepo extracts owner and repo name from a GitHub remote URL. Supports both HTTPS and SSH formats.
func ReplaceRepoInURL ¶
ReplaceRepoInURL swaps the repo name in a remote URL.
func RepoExists ¶
RepoExists checks whether a GitHub repository exists via the API. Returns true if the repo responds with 200, false on 404, error otherwise.
func ResolveTarget ¶
func ResolveTarget(parsed ParsedRepo, arg string) (int, error)
ResolveTarget computes the target version from a version argument. "v++" → current + 1 "v+1" → current + 1 (alias) "v15" → 15
func TargetRepoName ¶
TargetRepoName builds the full repo name for the target version.
func WalkBatchFromDir ¶
WalkBatchFromDir returns every immediate subdirectory of root that is itself a git repository (i.e. contains a `.git` entry).
Types ¶
type LocalRepoState ¶
type LocalRepoState struct {
OriginURL string // contents of .git/config [remote "origin"] url
HeadSHA string // resolved 40-char commit hash, or "" when unborn
}
LocalRepoState is the snapshot used to drive the "is an update available?" decision for one repo.
func ReadLocalRepoState ¶
func ReadLocalRepoState(repoPath string) (LocalRepoState, error)
ReadLocalRepoState parses .git/config for the origin URL and resolves HEAD to a commit SHA. Both fields may be empty individually (no origin set; unborn HEAD) without producing an error — only a missing .git entry is fatal.
type ParsedRepo ¶
ParsedRepo holds the decomposed parts of a versioned repo name.
func ParseRepoName ¶
func ParseRepoName(name string) ParsedRepo
ParseRepoName extracts the base name and version from a repo name. "macro-ahk-v11" → ("macro-ahk", 11, true) "macro-ahk" → ("macro-ahk", 1, false)
type RemoteUpdateCheck ¶
type RemoteUpdateCheck struct {
LocalVersion int // current -v<N> derived from the local folder name
RemoteVersion int // highest -v<M> that exists on GitHub (== local when none higher)
UpdateNeeded bool // true iff RemoteVersion > LocalVersion
TargetRepo string // "<owner>/<base>-v<RemoteVersion>" — empty when no update
}
RemoteUpdateCheck is the result of comparing a local repo to its versioned remote siblings.
func CheckRemoteForUpdate ¶
func CheckRemoteForUpdate(owner string, parsed ParsedRepo, ceiling int) (RemoteUpdateCheck, error)
CheckRemoteForUpdate probes GitHub for higher -v<M> siblings of the given parsed repo and returns whether a re-clone is warranted.
`owner` is the GitHub owner (org or user) parsed from the local repo's origin URL. `parsed` is the result of ParseRepoName on the local folder name. `ceiling` is the inclusive upper bound on M; pass DefaultRemoteProbeCeiling for the standard cap.
Returns UpdateNeeded=false when the repo has no -v<N> suffix at all (cannot reason about "next version" without a baseline).