repopath

package
v0.150.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package repopath models the canonical clone layout below a projects root: <root>/<host>/<org>/<repository>. The first level under the root is the literal forge hostname — never an alias — so a canonical clone's local path is invertible to its remote URL without reading any configuration or any repository remote.

It is the single source of truth for three questions every part of WB has to answer the same way: what may be a literal forge hostname, where a clone belongs (from its coordinate or its clone URL), and which {owner} directories a projects root holds. Nothing here shells out to Git or opens a repository; Owners reads directory names only, never a remote.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClonePathForURL

func ClonePathForURL(root, org, repo, cloneURL string) (string, error)

ClonePathForURL resolves where one repository's canonical clone is, or where it belongs when it does not exist yet.

An existing clone is used where it is — the literal host level first, then the legacy two-level placement — so a caller never creates a second copy beside a clone the machine already has. When no clone exists the destination is the literal host level the clone URL names. This is the single place that decision is made; every package that has both a coordinate and a clone URL resolves through it.

func IsForgeHost

func IsForgeHost(name string) bool

IsForgeHost reports whether name is a literal forge hostname usable as the first path level under a projects root: a dotted DNS name with at least two labels whose final label is an alphabetic top-level domain, optionally followed by an explicit port.

A bare owner name such as "dal-go" or "sneat-dev" is deliberately rejected. It is a syntactically valid single DNS label, so accepting it would let a legacy {owner}/{repository} directory masquerade as a forge — exactly the silent misread this requirement forbids.

func RemoteURLForLocalPath

func RemoteURLForLocalPath(root, path string) (string, error)

RemoteURLForLocalPath inverts one canonical clone path below root to the remote URL it corresponds to. It confirms the shape of the path and the literal hostname, and reads nothing else.

func SafeOwnerSegment

func SafeOwnerSegment(name string) bool

SafeOwnerSegment reports whether name can be one first or owner level segment of a canonical clone below a projects root: an ordinary safe name with no leading dot, or a literal forge hostname — which may carry an explicit port, so ":" is accepted in this position and nowhere else.

The two predicates must stay in step. A host level the placement rules accept but discovery filters out would make a clone that was deliberately created at <root>/github.com:8443/{org}/{repo} invisible to inventory, orphans and residue sweeps.

func SafeSegment

func SafeSegment(segment string, repository bool) bool

SafeSegment mirrors the segment rules WB applies to the org and repository levels of a clone path. Repository segments may start with a dot so a dot-named canonical repository (for example "acme/.github") keeps working.

Types

type Address

type Address struct {
	Host string
	Org  string
	Repo string
}

Address is one canonical clone address below a projects root. Host is the literal forge hostname (with an optional explicit port, e.g. "github.com:8443"); it is never an alias for a forge.

func FromCloneURL

func FromCloneURL(cloneURL, org, repo string) Address

FromCloneURL returns the canonical clone address a repository belongs at, given the URL it is cloned from. A clone URL whose host is a literal forge hostname places the clone at <host>/<org>/<repo>; anything else — a local path remote, an unparseable URL, or a host that cannot be a directory name — keeps the legacy two-level <org>/<repo> placement.

The host is never invented: it is read from the same URL the clone would be taken from, so a repository is never placed on a forge nobody named.

func FromLocalPath

func FromLocalPath(root, path string) (Address, error)

FromLocalPath inverts an absolute local path below root into its Address.

func Locate

func Locate(root, org, repo string) (Address, error)

Locate returns the canonical clone address for one {owner}/{repository} coordinate below root.

An existing clone is preferred: the literal host level first, then the legacy two-level placement, so a fleet that has not moved yet resolves to the clone it actually has rather than to a path nothing is at. When neither exists the legacy placement is predicted, because an unqualified coordinate carries no host to place it under — a host is knowable only from an existing clone or from a clone URL.

The same owner/repository on more than one forge is genuinely ambiguous — it is much of why the host level exists — so it is refused rather than resolved by an arbitrary pick.

func ParseRelative

func ParseRelative(relative string) (Address, error)

ParseRelative parses a root-relative canonical clone path (<host>/<org>/<repo>) into an Address. A path whose first level is not a literal forge hostname is rejected: a first-level entry that is not a valid hostname must be reported as a layout finding, never silently treated as a forge.

func (Address) EqualFold

func (address Address) EqualFold(other Address) bool

EqualFold reports whether two addresses name the same clone, ignoring case (forges and GitHub owners are case-insensitive).

func (Address) Path

func (address Address) Path(root string) string

Path is the address's absolute location below root.

func (Address) Relative

func (address Address) Relative() string

Relative is the address below the projects root: <host>/<org>/<repo>. A local-only origin names no host, and the relative form degrades to the legacy <org>/<repo> placement rather than inventing a forge level.

func (Address) RemoteURL

func (address Address) RemoteURL() string

RemoteURL is the remote URL the address inverts to. It is pure path arithmetic: WB derives it without reading any configuration or repository remote.

func (Address) Slug

func (address Address) Slug() string

Slug is the owner/repository identity without the host level. It is the identifier WB workflows carry in claims, work logs and filters.

func (Address) String

func (address Address) String() string

String renders the address the way it is written on disk.

type Owner

type Owner struct {
	Host string
	Name string
	Path string
}

Owner is one {owner} level under a projects root, together with the literal forge host level it was reached through. Host is empty for the legacy two-level placement.

func Owners

func Owners(root string) (owners []Owner, unreadable []string)

Owners lists the {owner} directories under root. A first-level entry that is a literal forge hostname is read through to its {org} level; every other first-level directory is the legacy {owner} level itself. Both shapes are returned together, so a fleet that has not adopted the host level stays fully discoverable and a migrated one is not read as empty.

Directories that could not be read are returned in unreadable as "<path>: <error>" diagnostics rather than failing the walk, because one unreadable directory must never hide all the others.

func (Owner) Relative

func (owner Owner) Relative() string

Relative is the owner's path below the projects root: {host}/{owner}, or {owner} alone for the legacy two-level placement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL