resolver

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: LGPL-3.0 Imports: 9 Imported by: 2

Documentation

Overview

Package resolver implements a way to resolve versions of software based on the provided criteria. The ideal use case is for package managers or anything else that needs ranges. Versions must meet semantic versioning requirements or otherwise be a branch/commit SHA.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnableToSatisfy = errors.New("no versions found that satisfy criteria")

ErrUnableToSatisfy is returned when no versions are found that satisfy the provided criteria.

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 denotes that a version does not actually relate to anything
	// in a Git repository. This is mainly meant for testing or scenarios
	// where you want to inject something in that is not a real version.
	//
	// This field is never set by the resolver in this package.
	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