Documentation
¶
Overview ¶
Package workspace provides a unified Source abstraction for resolving a repo identifier to an on-disk path. It encapsulates the three ingestion patterns used by go-code: local paths (with PATH_MAPPINGS translation), remote owner/repo slugs (clone), and WordPress.org plugin slugs (fetch).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RewritePath ¶
func RewritePath(path string, mappings []analyze.PathMapping) string
RewritePath applies mappings to path, substituting the first matching External prefix with the corresponding Internal prefix. Returns path unchanged when no mapping matches or mappings is empty.
func TranslateDirs ¶
func TranslateDirs(dirs []string, mappings []analyze.PathMapping) []string
TranslateDirs applies PATH_MAPPINGS translation to each directory in dirs, returning a new slice with each entry rewritten through mappings. Entries that have no matching mapping are returned unchanged.
Use this to translate AUTO_INDEX_DIRS (host-side paths from operator config) to container-internal paths before passing them to AutoIndex or EagerWarmRepos. Controlled by GO_CODE_AUTOINDEX_TRANSLATE=true; callers are responsible for checking that env flag before invoking this function.
Types ¶
type LocalSource ¶
type LocalSource struct {
// Path is the raw path as supplied by the caller (may be host-side).
Path string
// Mappings is the PATH_MAPPINGS translation table. May be nil.
Mappings []analyze.PathMapping
}
LocalSource resolves a bare on-disk path, applying PATH_MAPPINGS translation (External→Internal prefix substitution) before stat-checking the directory.
type RemoteSource ¶
type RemoteSource struct {
// Slug is the "owner/repo" identifier (resolved via forge.ExtractSlug).
Slug string
// RepoInput is the original user-supplied identifier (URL or slug).
// Used for forge detection so that GitLab and other forges are handled
// correctly. If empty, the resolver assumes GitHub forge — GitLab/Bitbucket
// callers MUST set this from the unnormalized input.
RepoInput string
// Ref is the optional git ref (branch, tag, commit) to check out.
Ref string
// DestDir is the workspace directory for temporary clones.
DestDir string
// TokenFunc returns an authentication token for the clone; may be nil.
TokenFunc func(ctx context.Context) (string, error)
// StaticToken is used when TokenFunc is nil. May be empty.
StaticToken string
}
RemoteSource clones a remote repo by owner/repo slug and returns the clone directory. The cleanup function removes the clone.
type Source ¶
type Source interface {
// Root returns an absolute on-disk path to the repo's source tree, along
// with a cleanup function (no-op for non-temporary sources). Callers must
// call cleanup() when done even if err is non-nil.
Root(ctx context.Context) (path string, cleanup func(), err error)
}
Source resolves a repo identifier to a usable on-disk path, applying PATH_MAPPINGS translation, slug-cloning, or local lookup as appropriate.
type WPSource ¶
type WPSource struct {
// Slug is the WordPress.org plugin slug (e.g. "woocommerce").
Slug string
// DestDir is the workspace directory for the downloaded plugin.
DestDir string
}
WPSource downloads a WordPress.org plugin by slug and returns the extracted directory. The cleanup function removes the temporary directory.