@@ -237,11 +237,6 @@ func NewToolFromHandler(
237237}
238238
239239type RequestDeps struct {
240- Client * gogithub.Client
241- GQLClient * githubv4.Client
242- RawClient * raw.Client
243- RepoAccessCache * lockdown.RepoAccessCache
244-
245240 // Static dependencies
246241 apiHosts utils.APIHostResolver
247242 version string
@@ -277,12 +272,12 @@ func NewRequestDeps(
277272
278273// GetClient implements ToolDependencies.
279274func (d * RequestDeps ) GetClient (ctx context.Context ) (* gogithub.Client , error ) {
280- if d .Client != nil {
281- return d .Client , nil
282- }
283-
284275 // extract the token from the context
285- token , _ := ghcontext .GetTokenInfo (ctx )
276+ tokenInfo , ok := ghcontext .GetTokenInfo (ctx )
277+ if ! ok {
278+ return nil , fmt .Errorf ("no token info in context" )
279+ }
280+ token := tokenInfo .Token
286281
287282 baseRestURL , err := d .apiHosts .BaseRESTURL (ctx )
288283 if err != nil {
@@ -303,12 +298,12 @@ func (d *RequestDeps) GetClient(ctx context.Context) (*gogithub.Client, error) {
303298
304299// GetGQLClient implements ToolDependencies.
305300func (d * RequestDeps ) GetGQLClient (ctx context.Context ) (* githubv4.Client , error ) {
306- if d .GQLClient != nil {
307- return d .GQLClient , nil
308- }
309-
310301 // extract the token from the context
311- token , _ := ghcontext .GetTokenInfo (ctx )
302+ tokenInfo , ok := ghcontext .GetTokenInfo (ctx )
303+ if ! ok {
304+ return nil , fmt .Errorf ("no token info in context" )
305+ }
306+ token := tokenInfo .Token
312307
313308 // Construct GraphQL client
314309 // We use NewEnterpriseClient unconditionally since we already parsed the API host
@@ -329,16 +324,11 @@ func (d *RequestDeps) GetGQLClient(ctx context.Context) (*githubv4.Client, error
329324 }
330325
331326 gqlClient := githubv4 .NewEnterpriseClient (graphqlURL .String (), gqlHTTPClient )
332- d .GQLClient = gqlClient
333327 return gqlClient , nil
334328}
335329
336330// GetRawClient implements ToolDependencies.
337331func (d * RequestDeps ) GetRawClient (ctx context.Context ) (* raw.Client , error ) {
338- if d .RawClient != nil {
339- return d .RawClient , nil
340- }
341-
342332 client , err := d .GetClient (ctx )
343333 if err != nil {
344334 return nil , err
@@ -350,7 +340,6 @@ func (d *RequestDeps) GetRawClient(ctx context.Context) (*raw.Client, error) {
350340 }
351341
352342 rawClient := raw .NewClient (client , rawURL )
353- d .RawClient = rawClient
354343
355344 return rawClient , nil
356345}
@@ -361,18 +350,13 @@ func (d *RequestDeps) GetRepoAccessCache(ctx context.Context) (*lockdown.RepoAcc
361350 return nil , nil
362351 }
363352
364- if d .RepoAccessCache != nil {
365- return d .RepoAccessCache , nil
366- }
367-
368353 gqlClient , err := d .GetGQLClient (ctx )
369354 if err != nil {
370355 return nil , err
371356 }
372357
373358 // Create repo access cache
374359 instance := lockdown .GetInstance (gqlClient , d .RepoAccessOpts ... )
375- d .RepoAccessCache = instance
376360 return instance , nil
377361}
378362
0 commit comments