github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/modules/git/git.go (about) 1 package git 2 3 import ( 4 "context" 5 6 "github.com/covergates/covergates/core" 7 "github.com/go-git/go-git/v5" 8 "github.com/go-git/go-git/v5/plumbing/transport/http" 9 "github.com/go-git/go-git/v5/storage/memory" 10 ) 11 12 // Service provides git operations 13 type Service struct{} 14 15 // Clone repository in memory 16 func (s *Service) Clone(ctx context.Context, URL, token string) (core.GitRepository, error) { 17 store := memory.NewStorage() 18 repo, err := git.CloneContext(ctx, store, nil, &git.CloneOptions{ 19 URL: URL, 20 Auth: &http.BasicAuth{ 21 Username: token, 22 Password: "x-oauth-basic", 23 }, 24 }) 25 if err != nil { 26 return nil, err 27 } 28 return &repository{ 29 gitRepository: repo, 30 }, nil 31 } 32 33 // PlainOpen a repository 34 func (s *Service) PlainOpen(ctx context.Context, path string) (core.GitRepository, error) { 35 repo, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{DetectDotGit: true}) 36 if err != nil { 37 return nil, err 38 } 39 return &repository{ 40 gitRepository: repo, 41 }, nil 42 }