git

package
Version: v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: AGPL-3.0 Imports: 24 Imported by: 3

Documentation

Overview

Package git provides access to git repositories.

Example
if err := fixtures.Init(); err != nil {
	panic(err)
}
defer fixtures.Clean()

fixture := fixtures.Basic().One()
fs := fixture.DotGit()
storer := filesystem.NewStorage(fs, cache.NewObjectLRU(cache.DefaultMaxSize))

// Create the git service with a repository loader that allows it to find
// a repository by ID.
srv := NewService(&StorerCommitLoader{storer})
changes, err := srv.GetChanges(context.Background(),
	&lookout.ChangesRequest{
		Base: &lookout.ReferencePointer{
			InternalRepositoryURL: "file:///myrepo",
			ReferenceName:         "notUsedInTestsButValidated",
			Hash:                  "af2d6a6954d532f8ffb47615169c8fdf9d383a1a",
		},
		Head: &lookout.ReferencePointer{
			InternalRepositoryURL: "file:///myrepo",
			ReferenceName:         "notUsedInTestsButValidated",
			Hash:                  "6ecf0ef2c2dffb796033e5a02219af86ec6584e5",
		},
	})
if err != nil {
	panic(err)
}

for changes.Next() {
	change := changes.Change()
	fmt.Printf("changed: %s\n", change.Head.Path)
}

if err := changes.Err(); err != nil {
	panic(err)
}

if err := changes.Close(); err != nil {
	panic(err)
}
Output:

changed: go/example.go
changed: php/crappy.php
changed: vendor/foo.go

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrRepositoryExists    = errors.NewKind("repository %s already exists")
	ErrRepositoryNotExists = errors.NewKind("repository %s not exists")
)
View Source
var ErrRefValidation = errors.NewKind("reference %v does not have a %s")

Functions

func NewChangeBlobScanner

func NewChangeBlobScanner(ctx context.Context, scanner lookout.ChangeScanner, base, head *object.Tree) *lookout.FnChangeScanner

NewChangeBlobScanner creates new FnChangeScanner

func NewChangeFilterScanner

func NewChangeFilterScanner(scanner lookout.ChangeScanner, include, exclude string) *lookout.FnChangeScanner

NewChangeFilterScanner creates new FnChangeScanner

func NewFileBlobScanner

func NewFileBlobScanner(ctx context.Context, scanner lookout.FileScanner, tree *object.Tree) *lookout.FnFileScanner

NewFileBlobScanner creates new FnFileScanner

func NewFileFilterScanner

func NewFileFilterScanner(ctx context.Context, scanner lookout.FileScanner, include, exclude string) *lookout.FnFileScanner

NewFileFilterScanner creates new FnFileScanner

Types

type AuthProvider added in v0.3.0

type AuthProvider interface {
	// GitAuth returns a go-git auth method for a repo
	GitAuth(ctx context.Context, repoInfo *lookout.RepositoryInfo) transport.AuthMethod
}

AuthProvider is an object that provides go-git auth methods

type CommitLoader

type CommitLoader interface {
	LoadCommits(context.Context, ...lookout.ReferencePointer) (
		[]*object.Commit, error)
}

type DiffTreeScanner

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

DiffTreeScanner is a scanner for files of diff between git trees

func NewDiffTreeScanner

func NewDiffTreeScanner(base, head *object.Tree) *DiffTreeScanner

NewDiffTreeScanner creates new DiffTreeScanner

func (*DiffTreeScanner) Change

func (s *DiffTreeScanner) Change() *lookout.Change

func (*DiffTreeScanner) Close

func (s *DiffTreeScanner) Close() error

func (*DiffTreeScanner) Err

func (s *DiffTreeScanner) Err() error

func (*DiffTreeScanner) Next

func (s *DiffTreeScanner) Next() bool

type Library

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

Library controls the persistence of multiple git repositories.

func NewLibrary

func NewLibrary(fs billy.Filesystem) *Library

NewLibrary creates a new Library based on the given filesystem.

func (*Library) Get

Get get the requested repository based on the given URL.

func (*Library) GetOrInit

func (l *Library) GetOrInit(ctx context.Context, url *lookout.RepositoryInfo) (
	*git.Repository, error)

GetOrInit get the requested repository based on the given URL, or inits a new repository.

func (*Library) Has

func (l *Library) Has(url *lookout.RepositoryInfo) (bool, error)

Has returns true if a repository with the given URL exists.

func (*Library) Init

Init inits a new repository for the given URL.

type LibraryCommitLoader

type LibraryCommitLoader struct {
	Library ReposCollectionHandler
	Syncer  Syncer
}

func (*LibraryCommitLoader) LoadCommits

func (l *LibraryCommitLoader) LoadCommits(
	ctx context.Context, rps ...lookout.ReferencePointer) (
	[]*object.Commit, error)

type LibrarySyncer added in v0.8.0

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

LibrarySyncer syncs the local copy of git repository for a given CommitRevision.

func (*LibrarySyncer) Sync added in v0.8.0

Sync syncs the local git repository to the given reference pointers.

type Service

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

Service implements data service interface on top of go-git

func NewService

func NewService(loader CommitLoader) *Service

NewService creates new git Service

func (*Service) GetChanges

func (r *Service) GetChanges(ctx context.Context, req *lookout.ChangesRequest) (
	lookout.ChangeScanner, error)

GetChanges returns a ChangeScanner that scans all changes according to the request.

func (*Service) GetFiles

func (r *Service) GetFiles(ctx context.Context, req *lookout.FilesRequest) (
	lookout.FileScanner, error)

GetFiles returns a FilesScanner that scans all files according to the request.

type StorerCommitLoader

type StorerCommitLoader struct {
	Storer storer.Storer
}

func NewStorerCommitLoader

func NewStorerCommitLoader(storer storer.Storer) *StorerCommitLoader

func (*StorerCommitLoader) LoadCommits

func (l *StorerCommitLoader) LoadCommits(ctx context.Context,
	rps ...lookout.ReferencePointer) ([]*object.Commit, error)

type Syncer

type Syncer interface {
	Sync(context.Context, ...lookout.ReferencePointer) error
}

func NewSyncer

func NewSyncer(l *Library, authProvider AuthProvider, fetchTimeout time.Duration) Syncer

NewSyncer returns a Syncer for the given Library. authProvider can be nil. A fetchTimeout of zero means no timeout.

type TreeScanner

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

TreeScanner is a scanner for files of git tree

func NewTreeScanner

func NewTreeScanner(tree *object.Tree) *TreeScanner

NewTreeScanner creates new TreeScanner

func (*TreeScanner) Change

func (s *TreeScanner) Change() *lookout.Change

func (*TreeScanner) Close

func (s *TreeScanner) Close() error

func (*TreeScanner) Err

func (s *TreeScanner) Err() error

func (*TreeScanner) File

func (s *TreeScanner) File() *lookout.File

func (*TreeScanner) Next

func (s *TreeScanner) Next() bool

Jump to

Keyboard shortcuts

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