locator

package
v0.0.0-...-2759aa6 Latest Latest
Warning

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

Go to latest
Published: May 27, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Store is the storage used by locator to store cloned configs.
	Store = datadir.Store("locator")
	// ConfigFile is the name of the config file for the locator.
	ConfigFile = "config.json"
)

Variables

View Source
var (
	ErrRepositoryNotFound = errors.New("repository not found")
	ErrEmptyBranch        = errors.New("empty branch")
)

related errors

View Source
var ErrInvalidCommit = errors.New("invalid commit")

ErrInvalidCommit is returned when the commit is invalid.

Functions

This section is empty.

Types

type Commit

type Commit struct {
	Hash    string
	Message string
}

type CommitList

type CommitList []Commit

func (CommitList) AsOptions

func (c CommitList) AsOptions() []string

type Git

type Git string

Git manages a given git repository. It holds the path to the repository path.

func (Git) Clone

func (g Git) Clone(remote, branch string) error

Clone clones the given repository and branch.

func (Git) Commits

func (g Git) Commits(branch string) (CommitList, error)

Commits returns the list of commits in the given branch.

func (Git) Read

func (g Git) Read(commit, path string) ([]byte, error)

Read reads a given file at a given revision and returns its contents.

func (Git) RepoExists

func (g Git) RepoExists() bool

RepoExists returns true if a repository exists at the given path.

func (Git) String

func (g Git) String() string

String returns the path to the repository.

type Locator

type Locator struct {
	Provider   Provider `json:"provider"`
	Protocol   string   `json:"protocol"`
	Repository string   `json:"repository"`
	Branch     string   `json:"branch"`
	Commit     string   `json:"commit"`
	Path       string   `json:"path"`
}

Locator contains the configuration for the locator. Do not 'omitempty' on fields in this struct, as we test if the Checksum contains all the fields by marshaling it to JSON. Therefore, if you omit empty fields, test may be false-negative.

func LoadFromStore

func LoadFromStore() (*Locator, error)

LoadFromStore loads a Locator from a config.json in store or fails if it does not exist.

func (*Locator) Checksum

func (l *Locator) Checksum() string

Checksum returns the unique id of the locator, it may be used as a file name.

func (*Locator) Clone

func (l *Locator) Clone() error

func (*Locator) Commits

func (l *Locator) Commits() (CommitList, error)

func (*Locator) Read

func (l *Locator) Read(file string) ([]byte, error)

Read a file from the repository.

func (*Locator) Save

func (l *Locator) Save() error

Save the locator to the config store.

type Provider

type Provider string

Provider is a locator provider such as GitHub, GitLab...

func (*Provider) Name

func (p *Provider) Name() string

Name returns the provider name in lowercase and without spaces (e.g. github, gitlab...)

func (*Provider) URL

func (p *Provider) URL(protocol, repository string) string

URL returns the repository url given a protocol (ssh, https) and a repository name

Jump to

Keyboard shortcuts

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