@@ -83,27 +83,16 @@ type GHClient struct {
8383}
8484
8585func NewGithubClient (ctx context.Context , authInfo AuthInfo , pendingRecheckTime time.Duration ) (GHClient , error ) {
86- var (
87- githubClient GHClient
88- err error
89- )
90-
9186 // If a GitHub token is provided, use it to authenticate in preference to
9287 // App authentication
9388 if authInfo .GithubToken != "" {
9489 log .Debug ("Using GitHub token for authentication" )
95- githubClient = AuthenticateWithToken (ctx , authInfo .GithubToken )
96- } else {
97- // Otherwise, use the App authentication flow
98- log .Debug ("Using GitHub App for authentication" )
99- githubClient , err = AuthenticateWithApp (ctx , authInfo .PrivateKey , authInfo .AppID , authInfo .InstallationID )
100- if err != nil {
101- return GHClient {}, err
102- }
90+ return AuthenticateWithToken (ctx , authInfo .GithubToken , pendingRecheckTime ), nil
10391 }
10492
105- githubClient .pendingRecheckTime = pendingRecheckTime
106- return githubClient , nil
93+ // Otherwise, use the App authentication flow
94+ log .Debug ("Using GitHub App for authentication" )
95+ return AuthenticateWithApp (ctx , authInfo .PrivateKey , authInfo .AppID , authInfo .InstallationID , pendingRecheckTime )
10796}
10897
10998func cachingRetryableTransport () http.RoundTripper {
@@ -117,27 +106,27 @@ func cachingRetryableTransport() http.RoundTripper {
117106}
118107
119108// AuthenticateWithToken authenticates with a GitHub token
120- func AuthenticateWithToken (ctx context.Context , token string ) GHClient {
109+ func AuthenticateWithToken (ctx context.Context , token string , pendingRecheckTime time. Duration ) GHClient {
121110 src := oauth2 .StaticTokenSource (
122111 & oauth2.Token {AccessToken : token },
123112 )
124113 ctx = context .WithValue (ctx , oauth2 .HTTPClient , & http.Client {Transport : cachingRetryableTransport ()})
125114 httpClient := oauth2 .NewClient (ctx , src )
126115 githubClient := github .NewClient (httpClient )
127116
128- return GHClient {client : githubClient }
117+ return GHClient {client : githubClient , pendingRecheckTime : pendingRecheckTime }
129118}
130119
131120// AuthenticateWithApp authenticates with a GitHub App
132- func AuthenticateWithApp (ctx context.Context , privateKey []byte , appID , installationID int64 ) (GHClient , error ) {
121+ func AuthenticateWithApp (ctx context.Context , privateKey []byte , appID , installationID int64 , pendingRecheckTime time. Duration ) (GHClient , error ) {
133122 itr , err := ghinstallation .New (cachingRetryableTransport (), appID , installationID , privateKey )
134123 if err != nil {
135124 return GHClient {}, fmt .Errorf ("failed to create transport: %w" , err )
136125 }
137126
138127 githubClient := github .NewClient (& http.Client {Transport : itr })
139128
140- return GHClient {client : githubClient }, nil
129+ return GHClient {client : githubClient , pendingRecheckTime : pendingRecheckTime }, nil
141130}
142131
143132func (c GHClient ) IsPRMergedOrClosed (ctx context.Context , owner , repo string , prNumber int ) (string , bool , int64 , error ) {
0 commit comments