@@ -75,10 +75,10 @@ type ClientCreator interface {
75
75
// * the installation ID is the ID that is shown in the URL of https://{githubURL}/settings/installations/{#}
76
76
// (navigate to the "installations" page without the # and go to the app's page to see the number)
77
77
// * the key bytes must be a PEM-encoded PKCS1 or PKCS8 private key for the application
78
- NewInstallationClient (installationID int64 ) (* github.Client , error )
78
+ NewInstallationClient (installationID int64 ) (* github.Client , TokenSource , error )
79
79
80
80
// NewInstallationV4Client returns an installation-authenticated v4 API client, similar to NewInstallationClient.
81
- NewInstallationV4Client (installationID int64 ) (* githubv4.Client , error )
81
+ NewInstallationV4Client (installationID int64 ) (* githubv4.Client , TokenSource , error )
82
82
83
83
// NewTokenClient returns a *github.Client that uses the passed in OAuth token for authentication.
84
84
NewTokenClient (token string ) (* github.Client , error )
@@ -209,9 +209,9 @@ func (c *clientCreator) NewAppV4Client() (*githubv4.Client, error) {
209
209
return client , nil
210
210
}
211
211
212
- func (c * clientCreator ) NewInstallationClient (installationID int64 ) (* github.Client , error ) {
212
+ func (c * clientCreator ) NewInstallationClient (installationID int64 ) (* github.Client , TokenSource , error ) {
213
213
base := c .newHTTPClient ()
214
- installation , transportError := newInstallation (c .integrationID , installationID , c .privKeyBytes , c .v3BaseURL )
214
+ installation , ghTransport , transportError := newInstallation (c .integrationID , installationID , c .privKeyBytes , c .v3BaseURL )
215
215
216
216
middleware := []ClientMiddleware {installation }
217
217
if c .cacheFunc != nil {
@@ -220,30 +220,34 @@ func (c *clientCreator) NewInstallationClient(installationID int64) (*github.Cli
220
220
221
221
client , err := c .newClient (base , middleware , fmt .Sprintf ("installation: %d" , installationID ), installationID )
222
222
if err != nil {
223
- return nil , err
223
+ return nil , nil , err
224
224
}
225
225
if * transportError != nil {
226
- return nil , * transportError
226
+ return nil , nil , * transportError
227
227
}
228
- return client , nil
228
+ return client , * ghTransport , nil
229
229
}
230
230
231
- func (c * clientCreator ) NewInstallationV4Client (installationID int64 ) (* githubv4.Client , error ) {
231
+ func (c * clientCreator ) NewInstallationV4Client (installationID int64 ) (* githubv4.Client , TokenSource , error ) {
232
232
base := c .newHTTPClient ()
233
- installation , transportError := newInstallation (c .integrationID , installationID , c .privKeyBytes , c .v3BaseURL )
233
+ installation , ghTransport , transportError := newInstallation (c .integrationID , installationID , c .privKeyBytes , c .v3BaseURL )
234
234
235
235
// The v4 API primarily uses POST requests (except for introspection queries)
236
236
// which we cannot cache, so don't construct the middleware
237
237
middleware := []ClientMiddleware {installation }
238
238
239
239
client , err := c .newV4Client (base , middleware , fmt .Sprintf ("installation: %d" , installationID ))
240
240
if err != nil {
241
- return nil , err
241
+ return nil , nil , err
242
242
}
243
243
if * transportError != nil {
244
- return nil , * transportError
244
+ return nil , nil , * transportError
245
245
}
246
- return client , nil
246
+ return client , * ghTransport , nil
247
+ }
248
+
249
+ type TokenSource interface {
250
+ Token (ctx context.Context ) (string , error )
247
251
}
248
252
249
253
func (c * clientCreator ) NewTokenClient (token string ) (* github.Client , error ) {
@@ -334,19 +338,22 @@ func newAppInstallation(integrationID int64, privKeyBytes []byte, v3BaseURL stri
334
338
return installation , & transportError
335
339
}
336
340
337
- func newInstallation (integrationID , installationID int64 , privKeyBytes []byte , v3BaseURL string ) (ClientMiddleware , * error ) {
341
+ func newInstallation (integrationID , installationID int64 , privKeyBytes []byte , v3BaseURL string ) (ClientMiddleware , * * ghinstallation. Transport , * error ) {
338
342
var transportError error
343
+ var itr * ghinstallation.Transport
339
344
installation := func (next http.RoundTripper ) http.RoundTripper {
340
- itr , err := ghinstallation .New (next , integrationID , installationID , privKeyBytes )
345
+ var err error
346
+ itr , err = ghinstallation .New (next , integrationID , installationID , privKeyBytes )
341
347
if err != nil {
342
348
transportError = err
349
+
343
350
return next
344
351
}
345
352
// leaving the v3 URL since this is used to refresh the token, not make queries
346
353
itr .BaseURL = strings .TrimSuffix (v3BaseURL , "/" )
347
354
return itr
348
355
}
349
- return installation , & transportError
356
+ return installation , & itr , & transportError
350
357
}
351
358
352
359
func cache (cacheFunc func () httpcache.Cache ) ClientMiddleware {
0 commit comments