repo

package
v0.1.9 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	MainBranchName = "main"
	RemoteName     = "origin"
)

Variables

View Source
var (
	ErrMissingCredentials = fmt.Errorf("missing credentials")
	ErrNotFound           = fmt.Errorf("not found")
)

Functions

This section is empty.

Types

type AuthProvider

type AuthProvider interface {
	GetUsername() string
	GetToken() string
}

AuthProvider provides access to basic auth credentials. Depending on the context (local vs ephemeral), credentials may be provided in different ways, thus the interface.

type CompileRequest

type CompileRequest struct {
	// Registry of protobuf types. This field is optional, if it does not exist, it will be instantiated.
	Registry *protoregistry.Types
	// Optional fields to filter features by, so as to not compile the entire world.
	NamespaceFilter, FeatureFilter string
	// Whether or not to persist the successfully compiled features
	Persist bool
	// If true, any generated compilation changes will overwrite previous features
	// even if there are type mismatches
	IgnoreBackwardsCompatibility bool
}

type FeatureCompilationResult

type FeatureCompilationResult struct {
	NamespaceName    string
	FeatureName      string
	CompiledFeature  *feature.CompiledFeature
	CompilationError error
}

func (*FeatureCompilationResult) Err

func (fcr *FeatureCompilationResult) Err() error

func (*FeatureCompilationResult) SummaryString

func (fcr *FeatureCompilationResult) SummaryString() string

type FeatureCompilationResults

type FeatureCompilationResults []*FeatureCompilationResult

func (FeatureCompilationResults) Err

func (fcrs FeatureCompilationResults) Err() error

type Repo

type Repo struct {
	Repo *git.Repository
	Wt   *git.Worktree
	Fs   billy.Filesystem

	Auth AuthProvider

	fs.Provider
	fs.ConfigWriter
	// contains filtered or unexported fields
}

Abstraction around git and github operations associated with the lekko configuration repo. This class can be used either by the cli, or by any other system that intends to manage operations around the lekko config repo.

func NewEphemeral

func NewEphemeral(url string, auth AuthProvider, branchName string) (*Repo, error)

Creates a new instance of Repo designed to work with ephemeral repos.

func NewLocal

func NewLocal(path string) (*Repo, error)

Creates a new instance of Repo designed to work with filesystem-based repos.

func NewLocalClone

func NewLocalClone(path, url string, auth AuthProvider) (*Repo, error)

Creates a local clone of a remote github config repository based on the given url at the provided path.

func (*Repo) Add

func (r *Repo) Add(ctx context.Context, ns, featureName string, fType feature.FeatureType) error

func (*Repo) BasicAuth

func (r *Repo) BasicAuth() transport.AuthMethod

func (*Repo) BranchName

func (r *Repo) BranchName() (string, error)

func (*Repo) BuildDynamicTypeRegistry

func (r *Repo) BuildDynamicTypeRegistry(ctx context.Context, protoDirPath string) (*protoregistry.Types, error)

func (*Repo) CheckoutRemoteBranch

func (r *Repo) CheckoutRemoteBranch(branchName string) error

Checks out the remote branch

func (*Repo) Cleanup

func (r *Repo) Cleanup(ctx context.Context, branchName *string) error

Cleans up all resources and references associated with the given branch on local and remote, if they exist. If branchName is nil, uses the current (non-master) branch. Will switch the current branch back to main, and pull from remote to ensure we are on the latest commit.

func (*Repo) CleanupBranch

func (r *Repo) CleanupBranch(ctx context.Context, branchName *string) error

func (*Repo) Commit

func (r *Repo) Commit(ctx context.Context, message string) (string, error)

Commit will take an optional commit message and push the changes in the local working directory to the remote branch.

func (*Repo) Compile

func (r *Repo) Compile(ctx context.Context, req *CompileRequest) ([]*FeatureCompilationResult, error)

func (*Repo) CompileFeature

func (r *Repo) CompileFeature(ctx context.Context, registry *protoregistry.Types, namespace, featureName string) (*feature.CompiledFeature, error)

func (*Repo) CreateOrRestore

func (r *Repo) CreateOrRestore(branchName string) error

If branchName already exists on remote, pull it down and switch to it. If branchName already exists on local, switch to it. If branchName doesn't exist, create it off of the main branch. This method is idempotent.

func (*Repo) CredentialsExist

func (r *Repo) CredentialsExist() error

func (*Repo) Eval

func (r *Repo) Eval(ctx context.Context, ns, featureName string, iCtx map[string]interface{}) (*anypb.Any, error)

func (*Repo) Fetch

func (r *Repo) Fetch(branchName string) error

func (*Repo) FindFeatureFiles

func (r *Repo) FindFeatureFiles(ctx context.Context, namespaceFilter, featureFilter string, verify bool) ([]*feature.FeatureFile, int, error)

func (*Repo) Format

func (r *Repo) Format(ctx context.Context) error

func (*Repo) FormatFeature

func (r *Repo) FormatFeature(ctx context.Context, ff feature.FeatureFile) error

func (*Repo) GenBranchName

func (r *Repo) GenBranchName() (string, error)

func (*Repo) GetContents

func (*Repo) GetDirContents

func (r *Repo) GetDirContents(_ context.Context, path string) ([]fs.ProviderFile, error)

func (*Repo) GetFeatureContents

func (r *Repo) GetFeatureContents(ctx context.Context, namespace, featureName string) (*feature.FeatureContents, error)

func (*Repo) GetFeatureFile

func (r *Repo) GetFeatureFile(ctx context.Context, namespace, featureName string) (*feature.FeatureFile, error)

func (*Repo) GetFeatureFiles

func (r *Repo) GetFeatureFiles(ctx context.Context, namespace string) ([]feature.FeatureFile, error)

func (*Repo) GetFeatureHash

func (r *Repo) GetFeatureHash(ctx context.Context, namespace, featureName string) (*plumbing.Hash, error)

Returns the hash of the proto bin file as indexed by the git tree. If there are uncommitted changes those won't be accounted for in the hash. The method is a reference, so I don't forget how to do this in the future (shubhit)

func (*Repo) GetFileContents

func (r *Repo) GetFileContents(_ context.Context, path string) ([]byte, error)

func (*Repo) GetPRInfo

func (r *Repo) GetPRInfo(ctx context.Context, branchName string, ghCli *gh.GithubClient) (*github.PullRequest, []*github.PullRequestReview, []*github.CheckRun, error)

func (*Repo) GetURL

func (r *Repo) GetURL() (*url.URL, error)

func (*Repo) HasReference

func (r *Repo) HasReference(refName plumbing.ReferenceName) (bool, error)

func (*Repo) HasRemote

func (r *Repo) HasRemote(branchName string) (bool, error)

func (*Repo) HumanReadableHash

func (r *Repo) HumanReadableHash() (string, error)

func (*Repo) IsNotExist

func (r *Repo) IsNotExist(err error) bool

func (*Repo) Logf

func (r *Repo) Logf(format string, a ...any)

func (*Repo) MainBranchHash

func (r *Repo) MainBranchHash() (string, error)

func (*Repo) Merge

func (r *Repo) Merge(ctx context.Context, prNum *int, ghCli *gh.GithubClient) error

func (*Repo) MkdirAll

func (r *Repo) MkdirAll(path string, perm os.FileMode) error

func (*Repo) Parse

func (r *Repo) Parse(ctx context.Context, ns, featureName string) error

func (*Repo) PersistFeature

func (r *Repo) PersistFeature(ctx context.Context, registry *protoregistry.Types, namespace string, f *feature.Feature, force bool) error

func (*Repo) Pull

func (r *Repo) Pull() error

func (*Repo) ReBuildDynamicTypeRegistry

func (r *Repo) ReBuildDynamicTypeRegistry(ctx context.Context, protoDirPath string) (*protoregistry.Types, error)

Actually regenerates the buf image, and writes it to the file system. Note: we don't have a way yet to run this from an ephemeral repo, because we need to first ensure that buf cmd line can be executed in the ephemeral env.

func (*Repo) Read

func (r *Repo) Read(path string) ([]byte, error)

func (*Repo) RemoveFeature

func (r *Repo) RemoveFeature(ctx context.Context, ns, featureName string) error

func (*Repo) RemoveIfExists

func (r *Repo) RemoveIfExists(path string) (bool, error)

func (*Repo) RemoveNamespace

func (r *Repo) RemoveNamespace(ctx context.Context, ns string) error

func (*Repo) Reset

func (r *Repo) Reset() error

Ensures wd is clean, checks out main branch and pulls from remote.

func (*Repo) RestoreWorkingDirectory

func (r *Repo) RestoreWorkingDirectory(hash string) error

Restores the entire repository to the git hash specified. The given hash must be a fully formed hash (e.g. 11586ea8bd20290ddc8fceaaab782b4d3dbe15c9). We do this by checking out the given hash in a detached head state, copying all the files (except the .git directory) to local memory, and writing out all the contents to our current working directory.

func (*Repo) Review

func (r *Repo) Review(ctx context.Context, title string, ghCli *gh.GithubClient) (string, error)

Review will open a pull request. It takes different actions depending on whether or not we are currently on main, and whether or not the working directory is clean.

func (*Repo) WorkingDirectoryHash

func (r *Repo) WorkingDirectoryHash() (*plumbing.Hash, error)

func (*Repo) WriteFile

func (r *Repo) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes data to the named file, creating it if necessary. If the file does not exist, WriteFile creates it with permissions perm (before umask); otherwise WriteFile truncates it before writing, without changing permissions.

Jump to

Keyboard shortcuts

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