diff --git a/pkg/connector/connector.go b/pkg/connector/connector.go index ea526d35..5433e37c 100644 --- a/pkg/connector/connector.go +++ b/pkg/connector/connector.go @@ -322,6 +322,16 @@ func newWithGithubApp(ctx context.Context, ghc *cfg.Github) (*GitHub, error) { return nil, err } + jwtts := oauth2.ReuseTokenSource( + &oauth2.Token{ + AccessToken: jwttoken, + Expiry: time.Now().Add(jwtExpiryTime), + }, + &appJWTTokenRefresher{ + appID: ghc.AppId, + privateKey: string(ghc.AppPrivatekeyPath), + }, + ) ts := oauth2.ReuseTokenSource( &oauth2.Token{ AccessToken: token.GetToken(), @@ -331,18 +341,17 @@ func newWithGithubApp(ctx context.Context, ghc *cfg.Github) (*GitHub, error) { ctx: ctx, instanceURL: ghc.InstanceUrl, installationID: installation.GetID(), - jwtTokenSource: oauth2.ReuseTokenSource( - &oauth2.Token{ - AccessToken: jwttoken, - Expiry: time.Now().Add(jwtExpiryTime), - }, - &appJWTTokenRefresher{ - appID: ghc.AppId, - privateKey: string(ghc.AppPrivatekeyPath), - }, - ), + jwtTokenSource: jwtts, }, ) + // override the appClient with the reuseTokenSource. + appClient, err = newGitHubClient(ctx, + ghc.InstanceUrl, + jwtts, + ) + if err != nil { + return nil, err + } ghClient, err := newGitHubClient(ctx, ghc.InstanceUrl, ts) if err != nil {