git

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2016 License: MPL-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaster = "master"

DefaultMaster is a default name for master branch.

View Source
const (
	// GitCommandDateLayout corresponds to `git log --date=format:%FT%T%z` date format.
	GitCommandDateLayout = "2006-01-02T15:04:05-0700"
)

Variables

View Source
var (
	// ErrorNotFound is returned by Get method if specified repository cannot be found.
	ErrorNotFound = errors.New("not found")
	// GithubToken is a context.Context key for Github auth token.
	GithubToken internal.TokenContextKey
)
View Source
var ErrorNotMirrored = errors.New("mirror not found")

ErrorNotMirrored is an error returned by Get if given repository does not exist.

Functions

func ParseRepositoryName

func ParseRepositoryName(fullName string) (string, string)

ParseRepositoryName returns owner and project name for given GitHub repository.

func SystemGit added in v1.0.3

func SystemGit() (systemGit, error)

SystemGit returns an object that wraps system git command and implements git.Command interface. If git is not found in PATH an error will be returned.

Types

type Command added in v1.0.3

type Command interface {
	IsRepository(fullPath string) bool
	CurrentBranch(fullPath string) string
	LastCommit(fullPath string) (Commit, error)
	CloneMirror(gitURL, fullPath string) error
	UpdateRemote(fullPath string) error
}

Command is the interface that wraps calls to Git.

type Commit

type Commit struct {
	SHA       string
	Message   string
	Author    string
	Committer string
	Date      time.Time
}

Commit represents a single commit in Git repository.

type GithubRepositories

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

GithubRepositories is a type intended to list and lookup GitHub repositories as well as setting webhooks.

func NewGithubRepositories

func NewGithubRepositories(ctx context.Context) (*GithubRepositories, error)

NewGithubRepositories creates and initializes a new instance of GithubRepositories. Context is expected to have GitHub auth token set with git.GithubToken as a key. Provided token is used to authorize requests to GitHub API and must be given "repo" or "public_repo" permissions. If token is not set or is empty an error will be returned.

func (*GithubRepositories) All

func (service *GithubRepositories) All() ([]*Repository, error)

All returns a list of GitHub repositories accessible with provided API token.

func (*GithubRepositories) Get

func (service *GithubRepositories) Get(fullName string) (*Repository, error)

Get retireves GitHub repositories details and returns an instance of Repository containing last commit information.

func (*GithubRepositories) Track

func (service *GithubRepositories) Track(fullName, callbackURL string) error

Track sets up "push" event GitHub webhook to be sent to callbackURL.

type MirrorService

type MirrorService interface {
	RepositoryService

	Create(name, url string) error
	Update(name string) error
}

MirrorService is a type that extends RepositoryService adding two more methods: Create and Update.

Mirror service is used to create new repository mirrors and update existing ones.

type MirroredRepositories

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

MirroredRepositories is a type that is intended for maintaining local Git repository mirrors located under the mirrorPath directory.

func NewMirroredRepositories

func NewMirroredRepositories(path string, gitCommand Command) *MirroredRepositories

NewMirroredRepositories creates and initializes an instance of MirroredRepositories reading and creating repositories under path directory.

func (*MirroredRepositories) All

func (service *MirroredRepositories) All() ([]*Repository, error)

All recursively searches and returns a list of repositories under mirrorPath. Unlike Get, All returns only basic information about Git repository, such as its name and the name of master branch.

func (*MirroredRepositories) Create

func (service *MirroredRepositories) Create(fullName, gitURL string) error

Create creates a local mirror of remote repository from gitURL by calling "git --mirror <gitURL> <fullName>".

func (*MirroredRepositories) Get

func (service *MirroredRepositories) Get(fullName string) (*Repository, error)

Get searches for a git repository in <mirrorPath>/<fullName> and returns the name of its name, master branch and lastest commit. If specified directory does not exist or not a git repository ErrorNotMirrored is returned.

func (*MirroredRepositories) Update

func (service *MirroredRepositories) Update(fullName string) error

Update downloads latest changes from remote repository into a local mirror discarding any changes that were pushed to mirror only. Update calls "git remote update" in <mirrorPath>/<fullName>.

type Repository

type Repository struct {
	// Full repository name. For GitHub repositories it's set to <user>/<repo>,
	// for local mirrors this is a path inside the mirror directory.
	FullName string
	// Description is optional and mostly applies to GitHub repositories.
	Description string
	// The name of master branch.
	Master string
	// A link to repository on GitHub.
	HTMLURL string
	// Remote URL.
	GitURL string

	// The latest commit from master.
	LatestMasterCommit *Commit
}

Repository represents single git repository.

func (*Repository) Mirrored

func (repo *Repository) Mirrored() bool

Mirrored returns true if this is a local repository mirror.

type RepositoryService

type RepositoryService interface {
	All() ([]*Repository, error)
	Get(name string) (*Repository, error)
}

RepositoryService is a type that wraps All and Get methods.

Repository service is used to list and lookup repositories. Two implementations

type TrackingService

type TrackingService interface {
	Track(name, callbackURL string) error
}

TrackingService is a type that wraps Track method.

Tracking service is used to set up tracking changes in a repository.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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