bufsync

package
v1.25.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrModuleDoesNotExist = errors.New("BSR module does not exist")

ErrModuleDoesNotExist is an error returned when looking for a remote module.

Functions

This section is empty.

Types

type ErrorHandler

type ErrorHandler interface {
	// InvalidModuleConfig is invoked by Syncer upon encountering a module
	// with an invalid module config.
	//
	// Returning an error will abort sync.
	InvalidModuleConfig(
		module Module,
		commit git.Commit,
		err error,
	) error
	// BuildFailure is invoked by Syncer upon encountering a module that fails
	// build.
	//
	// Returning an error will abort sync.
	BuildFailure(
		module Module,
		commit git.Commit,
		err error,
	) error
	// InvalidSyncPoint is invoked by Syncer upon encountering a module's branch
	// sync point that is invalid. A typical example is either a sync point that
	// point to a commit that cannot be found anymore, or the commit itself has
	// been corrupted.
	//
	// Returning an error will abort sync.
	InvalidSyncPoint(
		module Module,
		branch string,
		syncPoint git.Hash,
		err error,
	) error
}

ErrorHandler handles errors reported by the Syncer. If a non-nil error is returned by the handler, sync will abort in a partially-synced state.

type Module

type Module interface {
	// Dir is the path to the module relative to the repository root.
	Dir() string
	// RemoteIdentity is the identity of the remote module that the
	// local module is synced to.
	RemoteIdentity() bufmoduleref.ModuleIdentity
	// String is the string representation of this module.
	String() string
}

Module is a module that will be synced by Syncer.

func NewModule

func NewModule(dir string, identityOverride bufmoduleref.ModuleIdentity) (Module, error)

NewModule constructs a new module that can be synced with a Syncer.

type ModuleCommit

type ModuleCommit interface {
	// Identity is the identity of the module, accounting for any configured override.
	Identity() bufmoduleref.ModuleIdentity
	// Bucket is the bucket for the module.
	Bucket() storage.ReadBucket
	// Commit is the commit that the module is sourced from.
	Commit() git.Commit
	// Branch is the git branch that this module is sourced from.
	Branch() string
	// Tags are the git tags associated with Commit.
	Tags() []string
}

ModuleCommit is a module at a particular commit.

type ModuleDefaultBranchGetter added in v1.25.1

type ModuleDefaultBranchGetter func(
	ctx context.Context,
	module bufmoduleref.ModuleIdentity,
) (string, error)

ModuleDefaultBranchGetter is invoked before syncing, to make sure all modules that are about to be synced have a BSR default branch that matches the local git repo. If the BSR remote module does not exist, the implementation should return `ModuleDoesNotExistErr` error.

type SyncFunc

type SyncFunc func(ctx context.Context, commit ModuleCommit) error

SyncFunc is invoked by Syncer to process a sync point. If an error is returned, sync will abort.

type SyncPointResolver added in v1.22.0

type SyncPointResolver func(
	ctx context.Context,
	module bufmoduleref.ModuleIdentity,
	branch string,
) (git.Hash, error)

SyncPointResolver is invoked by Syncer to resolve a syncpoint for a particular module at a particular branch. If no syncpoint is found, this function returns nil. If an error is returned, sync will abort.

type SyncedGitCommitChecker added in v1.25.1

type SyncedGitCommitChecker func(
	ctx context.Context,
	module bufmoduleref.ModuleIdentity,
	commitHashes map[string]struct{},
) (map[string]struct{}, error)

SyncedGitCommitChecker is invoked when syncing branches to know which commits hashes from a set are already synced inthe BSR. It expects to receive the commit hashes that are synced already. If an error is returned, sync will abort.

type Syncer

type Syncer interface {
	// Sync syncs the repository using the provided SyncFunc. It processes
	// commits in reverse topological order, loads any configured named
	// modules, extracts any Git metadata for that commit, and invokes
	// SyncFunc with a ModuleCommit.
	//
	// Only commits/branches belonging to the remote named 'origin' are
	// processed. All tags are processed.
	Sync(context.Context, SyncFunc) error
}

Syncer syncs a modules in a git.Repository.

func NewSyncer

func NewSyncer(
	logger *zap.Logger,
	repo git.Repository,
	storageGitProvider storagegit.Provider,
	errorHandler ErrorHandler,
	options ...SyncerOption,
) (Syncer, error)

NewSyncer creates a new Syncer.

type SyncerOption

type SyncerOption func(*syncer) error

SyncerOption configures the creation of a new Syncer.

func SyncerWithAllBranches added in v1.25.1

func SyncerWithAllBranches() SyncerOption

SyncerWithAllBranches sets the syncer to sync all branches. Be default the syncer only processes commits in the current checked out branch.

func SyncerWithGitCommitChecker added in v1.25.1

func SyncerWithGitCommitChecker(checker SyncedGitCommitChecker) SyncerOption

SyncerWithGitCommitChecker configures a git commit checker, to know if a module has a given git hash alrady synced in a BSR instance.

func SyncerWithModule

func SyncerWithModule(module Module) SyncerOption

SyncerWithModule configures a Syncer to sync the specified module.

This option can be provided multiple times to sync multiple distinct modules.

func SyncerWithModuleDefaultBranchGetter added in v1.25.1

func SyncerWithModuleDefaultBranchGetter(getter ModuleDefaultBranchGetter) SyncerOption

SyncerWithModuleDefaultBranchGetter configures a getter for modules' default branch, to contrast a BSR repository default branch vs the local git repository branch. If left empty, the syncer skips this validation step.

func SyncerWithResumption added in v1.22.0

func SyncerWithResumption(resolver SyncPointResolver) SyncerOption

SyncerWithResumption configures a Syncer with a resumption using a SyncPointResolver.

Jump to

Keyboard shortcuts

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