@@ -21,6 +21,7 @@ import (
21
21
"net/url"
22
22
"regexp"
23
23
"strings"
24
+ "time"
24
25
25
26
"github.com/bradleyfalzon/ghinstallation"
26
27
"github.com/google/go-github/v32/github"
@@ -127,6 +128,7 @@ type clientCreator struct {
127
128
middleware []ClientMiddleware
128
129
cacheFunc func () httpcache.Cache
129
130
alwaysValidate bool
131
+ timeout time.Duration
130
132
}
131
133
132
134
var _ ClientCreator = & clientCreator {}
@@ -156,6 +158,13 @@ func WithClientCaching(alwaysValidate bool, cache func() httpcache.Cache) Client
156
158
}
157
159
}
158
160
161
+ // WithClientTimeout sets a request timeout for requests made by all created clients.
162
+ func WithClientTimeout (timeout time.Duration ) ClientOption {
163
+ return func (c * clientCreator ) {
164
+ c .timeout = timeout
165
+ }
166
+ }
167
+
159
168
// WithClientMiddleware adds middleware that is applied to all created clients.
160
169
func WithClientMiddleware (middleware ... ClientMiddleware ) ClientOption {
161
170
return func (c * clientCreator ) {
@@ -164,7 +173,7 @@ func WithClientMiddleware(middleware ...ClientMiddleware) ClientOption {
164
173
}
165
174
166
175
func (c * clientCreator ) NewAppClient () (* github.Client , error ) {
167
- base := & http. Client { Transport : http . DefaultTransport }
176
+ base := c . newHTTPClient ()
168
177
installation , transportError := newAppInstallation (c .integrationID , c .privKeyBytes , c .v3BaseURL )
169
178
170
179
middleware := []ClientMiddleware {installation }
@@ -183,7 +192,7 @@ func (c *clientCreator) NewAppClient() (*github.Client, error) {
183
192
}
184
193
185
194
func (c * clientCreator ) NewAppV4Client () (* githubv4.Client , error ) {
186
- base := & http. Client { Transport : http . DefaultTransport }
195
+ base := c . newHTTPClient ()
187
196
installation , transportError := newAppInstallation (c .integrationID , c .privKeyBytes , c .v3BaseURL )
188
197
189
198
// The v4 API primarily uses POST requests (except for introspection queries)
@@ -201,7 +210,7 @@ func (c *clientCreator) NewAppV4Client() (*githubv4.Client, error) {
201
210
}
202
211
203
212
func (c * clientCreator ) NewInstallationClient (installationID int64 ) (* github.Client , error ) {
204
- base := & http. Client { Transport : http . DefaultTransport }
213
+ base := c . newHTTPClient ()
205
214
installation , transportError := newInstallation (c .integrationID , installationID , c .privKeyBytes , c .v3BaseURL )
206
215
207
216
middleware := []ClientMiddleware {installation }
@@ -220,7 +229,7 @@ func (c *clientCreator) NewInstallationClient(installationID int64) (*github.Cli
220
229
}
221
230
222
231
func (c * clientCreator ) NewInstallationV4Client (installationID int64 ) (* githubv4.Client , error ) {
223
- base := & http. Client { Transport : http . DefaultTransport }
232
+ base := c . newHTTPClient ()
224
233
installation , transportError := newInstallation (c .integrationID , installationID , c .privKeyBytes , c .v3BaseURL )
225
234
226
235
// The v4 API primarily uses POST requests (except for introspection queries)
@@ -249,6 +258,13 @@ func (c *clientCreator) NewTokenV4Client(token string) (*githubv4.Client, error)
249
258
return c .newV4Client (tc , nil , "oauth token" )
250
259
}
251
260
261
+ func (c * clientCreator ) newHTTPClient () * http.Client {
262
+ return & http.Client {
263
+ Transport : http .DefaultTransport ,
264
+ Timeout : c .timeout ,
265
+ }
266
+ }
267
+
252
268
func (c * clientCreator ) newClient (base * http.Client , middleware []ClientMiddleware , details string , installID int64 ) (* github.Client , error ) {
253
269
applyMiddleware (base , [][]ClientMiddleware {
254
270
{setInstallationID (installID )},
0 commit comments