resolver

package
v0.7.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package resolver implements a way to resolve versions using a set of criteria. Note that only semantic versioning is supported for tags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Criteria

type Criteria struct {

	// Constraint is a semantic versioning constraint that the version
	// must satisfy.
	//
	// Example: ">=1.0.0 <2.0.0"
	Constraint string

	// Branch is the branch that the version must point to. This
	// constraint will only be satisfied if the branch currently points to
	// the commit being considered.
	//
	// If a branch is provided, it will always be used over other
	// versions. For this reason, top-level modules should only ever use
	// branches.
	Branch string
	// contains filtered or unexported fields
}

Criteria represents a set of criteria that a version must satisfy to be able to be selected.

func (*Criteria) Check

func (c *Criteria) Check(v *Version, prerelease, branch string) bool

Check returns true if the version satisfies the criteria. If a prerelease is included then the provided criteria will be mutated to support pre-releases as well as ensure that the prerelease string matches the provided version. If a branch is provided, then the criteria will always be satisfied unless the criteria is looking for a specific branch, in which case it will be satisfied only if the branches match.

func (*Criteria) Equal

func (c *Criteria) Equal(other *Criteria) bool

Equal returns true if the criteria is equal to the other criteria.

func (*Criteria) Parse

func (c *Criteria) Parse() error

Parse parses the criteria's constraint into a semver constraint. If the constraint is already parsed, this is a no-op.

func (*Criteria) String

func (c *Criteria) String() string

String returns a user-friendly representation of the criteria.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver is an instance of a version resolver that resolves versions based on the provided criteria. Version lists are fetched exactly once and are cached for the lifetime of the resolver.

func NewResolver

func NewResolver() *Resolver

NewResolver creates a new resolver instance.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, uri string, criteria ...*Criteria) (*Version, error)

Resolve returns the latest version matching the provided criteria. If multiple criteria are provided, the version must satisfy all of them. If no versions are found, an error is returned.

TODO(jaredallard): Return resolution errors as a type that can be unwrapped for getting information about why it failed.

type Version

type Version struct {
	// Commit is the underlying commit hash for this version.
	Commit string `yaml:"commit,omitempty"`

	// Tag is the underlying tag for this version, if set.
	Tag string `yaml:"tag,omitempty"`

	// Virtual is version that was injected either through the local
	// file-system or through a replacement. The value of this is set
	// depending on the context of how this was set. A virtual version is
	// never returned from a resolver.
	Virtual string `yaml:"virtual,omitempty"`

	// Branch is the underlying branch for this version, if set.
	Branch string `yaml:"branch,omitempty"`
	// contains filtered or unexported fields
}

Version represents a version found in a Git repository. Versions are only discovered if a tag or branch points to a commit (individual commits will never be automatically discovered unless they are manually passed in).

func (*Version) Equal

func (v *Version) Equal(other *Version) bool

Equal returns true if the two versions are equal.

func (*Version) GitRef

func (v *Version) GitRef() string

GitRef returns a Git reference that can be used to check out the version.

func (*Version) String

func (v *Version) String() string

String is a user-friendly representation of the version that can be used in error messages.

Jump to

Keyboard shortcuts

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