commit

package
v0.0.0-...-efe69f1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package commit contains methods for constructing/saving/retrieving commits.

Index

Constants

This section is empty.

Variables

View Source
var CommitSaveCols = []string{
	"Host", "Repository", "CommitHash", "PositionRef", "PositionNumber", "LastUpdatedTime",
}

CommitSaveCols is the set of columns written to in a commit save. Allocated here once to avoid reallocating on every commit save.

View Source
var (
	// ErrInvalidPositionFooter is returned when there is matching position footer
	// key, but its value doesn't match expected format.
	ErrInvalidPositionFooter = errors.New("invalid position footer format")
)

Functions

func Exists

func Exists(ctx context.Context, k Key) (bool, error)

Exists checks whether the commit key exists in the database.

func MustReadAllForTesting

func MustReadAllForTesting(ctx context.Context) map[Key]Commit

MustReadAllForTesting reads all commits for testing, e.g. to assert all expected commits were inserted.

Must be called in a spanner transactional context. Do not use in production, will not scale.

func MustSetForTesting

func MustSetForTesting(ctx context.Context, cs ...Commit)

MustSetForTesting replaces the set of stored commits to match the given set.

func ShouldMatchCommits

func ShouldMatchCommits(commits []Commit) comparison.Func[map[Key]Commit]

ShouldMatchCommits returns a comparison.Func which checks if the expected commits matches the actual commits. The order of the commits does not matter.

func ShouldMatchCommitsIn

func ShouldMatchCommitsIn(commits ...Commit) comparison.Func[Commit]

ShouldMatchCommitsIn returns a comparison.Func which checks if the actual actual commit matches any of the expected commits.

func ShouldMatchGitCommit

func ShouldMatchGitCommit(commit GitCommit) comparison.Func[GitCommit]

ShouldMatchGitCommit returns a comparison.Func which checks if the expected GitCommit matches the actual GitCommit.

func ShouldMatchKey

func ShouldMatchKey(key Key) comparison.Func[Key]

ShouldMatchKey returns a comparison.Func which checks if the expected commit key matches the actual commit key.

Types

type Commit

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

Commit represents a row in the Commits table.

func NewFromGitCommit

func NewFromGitCommit(gitCommit GitCommit) Commit

NewFromGitCommit creates a new Commit from a GitCommit.

N.B. if the GitCommit does not have a valid git commit position, the returned Commit will not have a commit position either.

func ReadByKey

func ReadByKey(ctx context.Context, k Key) (commits Commit, err error)

ReadByKey retrieves a commit from the database given the commit key.

func ReadByPosition

func ReadByPosition(ctx context.Context, opts ReadByPositionOpts) (commits Commit, err error)

ReadByPosition retrieves a commit from the database given the commit position.

When there are multiple matches, only the first match (arbitrary order) is returned. If no commit is found, returns spanutil.ErrNotExists.

func (Commit) Key

func (c Commit) Key() Key

Key returns the primary key of the commit in the Commits table.

func (Commit) Position

func (c Commit) Position() *Position

Position returns the position of the commit along a ref.

func (Commit) Save

func (c Commit) Save() *spanner.Mutation

Save creates a mutation to save/overwrite the commit into the Commits table. The commit should've already been verified during struct creation.

type GitCommit

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

func NewGitCommit

func NewGitCommit(host, repository string, commit *git.Commit) (GitCommit, error)

NewGitCommit creates a new GitCommit.

func (GitCommit) Key

func (c GitCommit) Key() Key

Key returns the key of the commit.

func (GitCommit) Position

func (c GitCommit) Position() (*Position, error)

Position extracts the commit position from the commit message.

type Key

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

Key denotes the primary key for the Commits table.

func NewKey

func NewKey(host, repository, commitHash string) (Key, error)

NewKey creates a new Commit key.

func (Key) CommitHash

func (k Key) CommitHash() string

CommitHash returns the commit hash.

func (Key) URL

func (k Key) URL() string

URL returns the URL for the commit.

type Position

type Position struct {
	// Ref is the ref where the commit position is based on.
	Ref string
	// Number is the commit position number.
	Number int64
}

Position represents the position of a commit along a ref.

type ReadByPositionOpts

type ReadByPositionOpts struct {
	// Required. Host is the gitiles host of the repository.
	Host string
	// Required. Repository is the Gitiles project of the commit.
	Repository string
	// Required. Position is the position of the commit along a ref.
	Position Position
}

ReadByPositionOpts is the option to read by

Jump to

Keyboard shortcuts

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