1
1
package github
2
2
3
3
import (
4
+ "context"
4
5
"net/http"
5
6
"strconv"
6
7
"strings"
7
8
"sync"
8
9
"time"
9
10
10
11
"github.com/src-d/lookout"
12
+ "github.com/src-d/lookout/service/git"
11
13
"github.com/src-d/lookout/util/cache"
12
14
"github.com/src-d/lookout/util/ctxlog"
13
15
14
16
"github.com/google/go-github/github"
15
17
"github.com/gregjones/httpcache"
18
+ "gopkg.in/src-d/go-git.v4/plumbing/transport"
16
19
log "gopkg.in/src-d/go-log.v1"
17
20
)
18
21
@@ -214,16 +217,36 @@ func (p *ClientPool) notify(e ClientPoolEvent) {
214
217
}
215
218
}
216
219
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
+
217
234
// Client is a wrapper for github.Client that supports cache and provides rate limit information
218
235
type Client struct {
219
236
* github.Client
220
237
cache * cache.ValidableCache
221
238
limitRT * limitRoundTripper
222
239
watchMinInterval time.Duration
240
+ gitAuth gitAuthFn
223
241
}
224
242
225
243
// 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 {
227
250
limitRT := & limitRoundTripper {
228
251
Base : t ,
229
252
}
@@ -247,6 +270,7 @@ func NewClient(t http.RoundTripper, cache *cache.ValidableCache, watchMinInterva
247
270
cache : cache ,
248
271
limitRT : limitRT ,
249
272
watchMinInterval : interval ,
273
+ gitAuth : gitAuth ,
250
274
}
251
275
}
252
276
0 commit comments