git

package
v0.2.7 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2020 License: MPL-2.0-no-copyleft-exception Imports: 11 Imported by: 0

Documentation

Overview

Package git implements functionality to work with git and GitHub.

To leverage it, create a RepoManager and call Init() on it with the appropriate arguments. Then, you can manage git repositories as a collection of items coming from GitHub.

The filesystem is organized like so:

  • rootpath
  • parentOrg1
  • repo1
  • repo1
  • parentOrg2
  • repo1

No original clones of the forks are kept. These are stored as remotes in each parent repository. This allows us to keep the filesystem footprint simple as well as keeping a cache for each fork in a reliable way.

Clones are done over HTTPS with a login script that is used in conjunction with the token provided from the queuesvc to auth against github. SSH cloning has a lot of intermediate caching challenges that we were trying to avoid for future works; this is aside from how hard it can be to orchestrate automated SSH without leaking secrets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	LoginScriptPath string `yaml:"login_script_path"`
	BaseRepoPath    string `yaml:"base_repo_path"`
}

Config manages various one-off tidbits about the runner's git paths and other data. You must manually merge this with your runner's configuration if you wish to use the runner framework, see fw/config documentation for more information.

func (*Config) Validate

func (rc *Config) Validate() *errors.Error

Validate corrects or errors out when the configuration doesn't match expectations.

type RepoManager

type RepoManager struct {
	// Config addresses the configuration of certain git-centric items such as
	// the root repo path
	Config Config
	// Logger is the logsvc client
	Logger *log.SubLogger
	// Log is an IO stream that will be sent output from git.
	Log io.Writer
	// AccessToken is the github access token used to auth over https.
	AccessToken string
	// Env is the set of environ(7)-style environment variable listings. They
	// will be appended to each git call.
	Env []string

	//
	// The following fields are populated at init time and should be left blank
	// or they will be overwritten.
	//
	// RepoPath is the path to the repository, computed from name and base path.
	RepoPath string
	// RepoName is the parent repo in owner/repo format.
	RepoName string
	// ForkRepoName is the name of the fork repo in owner/repo format
	ForkRepoName string
	// ForkRemote is the computed owner name from the fork repo definition.
	ForkRemote string
}

RepoManager manages a series of repositories. Call Init() before using it.

func (*RepoManager) AddOrFetchFork

func (rm *RepoManager) AddOrFetchFork() *errors.Error

AddOrFetchFork retrieves the fork's contents, or adds the fork as a remote, and then does that.

func (*RepoManager) Checkout

func (rm *RepoManager) Checkout(ref string) *errors.Error

Checkout sets the working copy to the ref provided.

func (*RepoManager) CloneOrFetch

func (rm *RepoManager) CloneOrFetch(ctx context.Context, defaultBranch string) *errors.Error

CloneOrFetch either clones a new repository, or fetches from an existing origin.

func (*RepoManager) Init

func (rm *RepoManager) Init(config Config, log *log.SubLogger, repoName, forkRepoName string) *errors.Error

Init initializes the repomanager for use. Must be called before using other functions.

func (*RepoManager) Merge

func (rm *RepoManager) Merge(ref string) (retErr *errors.Error)

Merge merges the ref into the currently checked out ref.

func (*RepoManager) Rebase

func (rm *RepoManager) Rebase(ref string) (retErr *errors.Error)

Rebase is similar to merge with rollback capability. Otherwise it's plain rebase.

func (*RepoManager) Run

func (rm *RepoManager) Run(command ...string) *errors.Error

Run runs a command, piping output to the log.

Jump to

Keyboard shortcuts

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