Documentation
¶
Overview ¶
Package codehost defines the interface implemented by a code hosting source, along with support code for use by implementations.
Index ¶
- Constants
- Variables
- func AllHex(rev string) bool
- func Run(ctx context.Context, dir string, cmdline ...any) ([]byte, error)
- func RunWithArgs(ctx context.Context, args RunArgs) ([]byte, error)
- func ShortenSHA1(rev string) string
- func WorkDir(ctx context.Context, typ, name string) (dir, lockfile string, err error)
- type Origin
- type Repo
- type RevInfo
- type RunArgs
- type RunError
- type Tag
- type Tags
- type UnknownRevisionError
- type VCSError
Constants ¶
const ( MaxGoMod = 16 << 20 MaxLICENSE = 16 << 20 MaxZipFile = 500 << 20 )
Downloaded size limits.
Variables ¶
var ErrNoCommits error = noCommitsError{}
ErrNoCommits is an error equivalent to fs.ErrNotExist indicating that a given repository or module contains no commits.
Functions ¶
func Run ¶
Run runs the command line in the given directory (an empty dir means the current directory). It returns the standard output and, for a non-zero exit, a *RunError indicating the command, exit status, and standard error. Standard error is unavailable for commands that exit successfully.
func RunWithArgs ¶ added in v1.23.0
RunWithArgs is the same as Run but it also accepts additional arguments.
func ShortenSHA1 ¶
ShortenSHA1 shortens a SHA1 hash (40 hex digits) to the canonical length used in pseudo-versions (12 hex digits).
Types ¶
type Origin ¶
type Origin struct { VCS string `json:",omitempty"` URL string `json:",omitempty"` Subdir string `json:",omitempty"` Hash string `json:",omitempty"` // If TagSum is non-empty, then the resolution of this module version // depends on the set of tags present in the repo, specifically the tags // of the form TagPrefix + a valid semver version. // If the matching repo tags and their commit hashes still hash to TagSum, // the Origin is still valid (at least as far as the tags are concerned). // The exact checksum is up to the Repo implementation; see (*gitRepo).Tags. TagPrefix string `json:",omitempty"` TagSum string `json:",omitempty"` // If Ref is non-empty, then the resolution of this module version // depends on Ref resolving to the revision identified by Hash. // If Ref still resolves to Hash, the Origin is still valid (at least as far as Ref is concerned). // For Git, the Ref is a full ref like "refs/heads/main" or "refs/tags/v1.2.3", // and the Hash is the Git object hash the ref maps to. // Other VCS might choose differently, but the idea is that Ref is the name // with a mutable meaning while Hash is a name with an immutable meaning. Ref string `json:",omitempty"` // If RepoSum is non-empty, then the resolution of this module version // failed due to the repo being available but the version not being present. // This depends on the entire state of the repo, which RepoSum summarizes. // For Git, this is a hash of all the refs and their hashes. RepoSum string `json:",omitempty"` }
An Origin describes the provenance of a given repo method result. It can be passed to CheckReuse (usually in a different go command invocation) to see whether the result remains up-to-date.
type Repo ¶
type Repo interface { CheckReuse(ctx context.Context, old *Origin, subdir string) error Tags(ctx context.Context, prefix string) (*Tags, error) Stat(ctx context.Context, rev string) (*RevInfo, error) Latest(ctx context.Context) (*RevInfo, error) ReadFile(ctx context.Context, rev, file string, maxSize int64) (data []byte, err error) ReadZip(ctx context.Context, rev, subdir string, maxSize int64) (zip io.ReadCloser, err error) RecentTag(ctx context.Context, rev, prefix string, allowed func(tag string) bool) (tag string, err error) DescendsFrom(ctx context.Context, rev, tag string) (bool, error) }
A Repo represents a code hosting source. Typical implementations include local version control repositories, remote version control servers, and code hosting sites.
A Repo must be safe for simultaneous use by multiple goroutines, and callers must not modify returned values, which may be cached and shared.
type RevInfo ¶
type RevInfo struct { Origin *Origin Name string Short string Version string Time time.Time Tags []string }
A RevInfo describes a single revision in a source code repository.
type UnknownRevisionError ¶
type UnknownRevisionError struct {
Rev string
}
UnknownRevisionError is an error equivalent to fs.ErrNotExist, but for a revision rather than a file.
func (*UnknownRevisionError) Error ¶
func (e *UnknownRevisionError) Error() string
func (UnknownRevisionError) Is ¶
func (UnknownRevisionError) Is(err error) bool
type VCSError ¶
type VCSError struct {
Err error
}
A VCSError indicates an error using a version control system. The implication of a VCSError is that we know definitively where to get the code, but we can't access it due to the error. The caller should report this error instead of continuing to probe other possible module paths.
TODO(golang.org/issue/31730): See if we can invert this. (Return a distinguished error for “repo not found” and treat everything else as terminal.)