@@ -83,27 +83,16 @@ type GHClient struct {
83
83
}
84
84
85
85
func NewGithubClient (ctx context.Context , authInfo AuthInfo , pendingRecheckTime time.Duration ) (GHClient , error ) {
86
- var (
87
- githubClient GHClient
88
- err error
89
- )
90
-
91
86
// If a GitHub token is provided, use it to authenticate in preference to
92
87
// App authentication
93
88
if authInfo .GithubToken != "" {
94
89
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
103
91
}
104
92
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 )
107
96
}
108
97
109
98
func cachingRetryableTransport () http.RoundTripper {
@@ -117,27 +106,27 @@ func cachingRetryableTransport() http.RoundTripper {
117
106
}
118
107
119
108
// 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 {
121
110
src := oauth2 .StaticTokenSource (
122
111
& oauth2.Token {AccessToken : token },
123
112
)
124
113
ctx = context .WithValue (ctx , oauth2 .HTTPClient , & http.Client {Transport : cachingRetryableTransport ()})
125
114
httpClient := oauth2 .NewClient (ctx , src )
126
115
githubClient := github .NewClient (httpClient )
127
116
128
- return GHClient {client : githubClient }
117
+ return GHClient {client : githubClient , pendingRecheckTime : pendingRecheckTime }
129
118
}
130
119
131
120
// 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 ) {
133
122
itr , err := ghinstallation .New (cachingRetryableTransport (), appID , installationID , privateKey )
134
123
if err != nil {
135
124
return GHClient {}, fmt .Errorf ("failed to create transport: %w" , err )
136
125
}
137
126
138
127
githubClient := github .NewClient (& http.Client {Transport : itr })
139
128
140
- return GHClient {client : githubClient }, nil
129
+ return GHClient {client : githubClient , pendingRecheckTime : pendingRecheckTime }, nil
141
130
}
142
131
143
132
func (c GHClient ) IsPRMergedOrClosed (ctx context.Context , owner , repo string , prNumber int ) (string , bool , int64 , error ) {
0 commit comments