github.com/covergates/covergates@v0.2.2-0.20201009050117-42ef8a19fb95/modules/scm/content.go (about) 1 package scm 2 3 import ( 4 "context" 5 "sync" 6 7 "github.com/covergates/covergates/core" 8 "github.com/drone/go-scm/scm" 9 ) 10 11 type contentService struct { 12 sync.Mutex 13 client *scm.Client 14 git core.Git 15 scm core.SCMProvider 16 } 17 18 func (service *contentService) ListAllFiles( 19 ctx context.Context, 20 user *core.User, 21 repo, ref string, 22 ) ([]string, error) { 23 client := service.client 24 ctx = withUser(ctx, service.scm, user) 25 commit, _, err := client.Git.FindCommit(ctx, repo, ref) 26 if err != nil { 27 return nil, err 28 } 29 r, _, err := client.Repositories.Find(ctx, repo) 30 if err != nil { 31 return nil, err 32 } 33 token := userToken(service.scm, user) 34 gitRepo, err := service.git.Clone(ctx, r.Clone, token.Token) 35 if err != nil { 36 return nil, err 37 } 38 return gitRepo.ListAllFiles(commit.Sha) 39 } 40 41 func (service *contentService) Find(ctx context.Context, user *core.User, repo, path, ref string) ([]byte, error) { 42 client := service.client 43 ctx = withUser(ctx, service.scm, user) 44 content, _, err := client.Contents.Find(ctx, repo, path, ref) 45 return content.Data, err 46 }