11package github
22
33import (
4+ "context"
45 "net/http"
56 "strconv"
67 "strings"
78 "sync"
89 "time"
910
1011 "github.com/src-d/lookout"
12+ "github.com/src-d/lookout/service/git"
1113 "github.com/src-d/lookout/util/cache"
1214 "github.com/src-d/lookout/util/ctxlog"
1315
1416 "github.com/google/go-github/github"
1517 "github.com/gregjones/httpcache"
18+ "gopkg.in/src-d/go-git.v4/plumbing/transport"
1619 log "gopkg.in/src-d/go-log.v1"
1720)
1821
@@ -214,16 +217,36 @@ func (p *ClientPool) notify(e ClientPoolEvent) {
214217 }
215218}
216219
220+ var _ git.AuthProvider = & ClientPool {}
221+
222+ // GitAuth returns a go-git auth method for a repo
223+ func (p * ClientPool ) GitAuth (ctx context.Context , repoInfo * lookout.RepositoryInfo ) transport.AuthMethod {
224+ c , ok := p .Client (repoInfo .Username , repoInfo .Name )
225+ if ! ok {
226+ return nil
227+ }
228+
229+ return c .gitAuth (ctx )
230+ }
231+
232+ type gitAuthFn = func (ctx context.Context ) transport.AuthMethod
233+
217234// Client is a wrapper for github.Client that supports cache and provides rate limit information
218235type Client struct {
219236 * github.Client
220237 cache * cache.ValidableCache
221238 limitRT * limitRoundTripper
222239 watchMinInterval time.Duration
240+ gitAuth gitAuthFn
223241}
224242
225243// NewClient creates new Client
226- func NewClient (t http.RoundTripper , cache * cache.ValidableCache , watchMinInterval string ) * Client {
244+ func NewClient (
245+ t http.RoundTripper ,
246+ cache * cache.ValidableCache ,
247+ watchMinInterval string ,
248+ gitAuth gitAuthFn ,
249+ ) * Client {
227250 limitRT := & limitRoundTripper {
228251 Base : t ,
229252 }
@@ -247,6 +270,7 @@ func NewClient(t http.RoundTripper, cache *cache.ValidableCache, watchMinInterva
247270 cache : cache ,
248271 limitRT : limitRT ,
249272 watchMinInterval : interval ,
273+ gitAuth : gitAuth ,
250274 }
251275}
252276
0 commit comments