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 ¶
- Variables
- func NewChangeBlobScanner(ctx context.Context, scanner lookout.ChangeScanner, base, head *object.Tree) *lookout.FnChangeScanner
- func NewChangeFilterScanner(scanner lookout.ChangeScanner, include, exclude string) *lookout.FnChangeScanner
- func NewFileBlobScanner(ctx context.Context, scanner lookout.FileScanner, tree *object.Tree) *lookout.FnFileScanner
- func NewFileFilterScanner(ctx context.Context, scanner lookout.FileScanner, include, exclude string) *lookout.FnFileScanner
- type AuthProvider
- type CommitLoader
- type DiffTreeScanner
- type Library
- func (l *Library) Get(ctx context.Context, url *lookout.RepositoryInfo) (*git.Repository, error)
- func (l *Library) GetOrInit(ctx context.Context, url *lookout.RepositoryInfo) (*git.Repository, error)
- func (l *Library) Has(url *lookout.RepositoryInfo) (bool, error)
- func (l *Library) Init(ctx context.Context, url *lookout.RepositoryInfo) (*git.Repository, error)
- type LibraryCommitLoader
- type LibrarySyncer
- type ReposCollectionHandler
- type Service
- type StorerCommitLoader
- type Syncer
- type TreeScanner
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrRepositoryExists = errors.NewKind("repository %s already exists") ErrRepositoryNotExists = errors.NewKind("repository %s not exists") )
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 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 ¶
func (l *Library) Get(ctx context.Context, url *lookout.RepositoryInfo) (*git.Repository, error)
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 ¶
func (l *Library) Init(ctx context.Context, url *lookout.RepositoryInfo) (*git.Repository, error)
Init inits a new repository for the given URL.
type LibraryCommitLoader ¶
type LibraryCommitLoader struct { Library ReposCollectionHandler Syncer Syncer }
func NewLibraryCommitLoader ¶
func NewLibraryCommitLoader(l ReposCollectionHandler, s Syncer) *LibraryCommitLoader
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
func (s *LibrarySyncer) Sync(ctx context.Context, rps ...lookout.ReferencePointer) error
Sync syncs the local git repository to the given reference pointers.
type ReposCollectionHandler ¶ added in v0.8.0
type ReposCollectionHandler interface { GetOrInit(context.Context, *lookout.RepositoryInfo) (*git.Repository, error) Init(context.Context, *lookout.RepositoryInfo) (*git.Repository, error) Has(*lookout.RepositoryInfo) (bool, error) Get(context.Context, *lookout.RepositoryInfo) (*git.Repository, error) }
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements data service interface on top of go-git
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 ¶
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 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