@@ -94,18 +94,11 @@ func (o *teamResourceType) List(ctx context.Context, parentID *v2.ResourceId, pt
9494 return nil , "" , nil , err
9595 }
9696
97- cli := o .client
98- if len (o .app .appInstallationClient ) > 0 {
99- i , err := strconv .ParseInt (parentID .GetResource (), 10 , 64 )
100- if err != nil {
101- return nil , "" , nil , err
102- }
103- var ok bool
104- cli , ok = o .app .appInstallationClient [i ]
105- if ! ok {
106- return nil , "" , nil , fmt .Errorf ("organization: %d doesn't exist" , i )
107- }
97+ cli , err := getClient (o .client , o .app , parentID .GetResource ())
98+ if err != nil {
99+ return nil , "" , nil , err
108100 }
101+
109102 teams , resp , err := cli .Teams .ListTeams (ctx , orgName , opts )
110103 if err != nil {
111104 return nil , "" , nil , fmt .Errorf ("github-connector: failed to list teams: %w" , err )
@@ -180,17 +173,9 @@ func (o *teamResourceType) Grants(ctx context.Context, resource *v2.Resource, pT
180173 return nil , "" , nil , fmt .Errorf ("error fetching orgID from team profile" )
181174 }
182175
183- cli := o .client
184- if len (o .app .appInstallationClient ) > 0 {
185- i , err := strconv .ParseInt (resource .GetParentResourceId ().GetResource (), 10 , 64 )
186- if err != nil {
187- return nil , "" , nil , err
188- }
189- var ok bool
190- cli , ok = o .app .appInstallationClient [i ]
191- if ! ok {
192- return nil , "" , nil , fmt .Errorf ("organization: %d doesn't exist" , i )
193- }
176+ cli , err := getClient (o .client , o .app , resource .GetParentResourceId ().GetResource ())
177+ if err != nil {
178+ return nil , "" , nil , err
194179 }
195180
196181 org , _ , err := cli .Organizations .GetByID (ctx , orgID )
@@ -299,17 +284,9 @@ func (o *teamResourceType) Grant(ctx context.Context, principal *v2.Resource, en
299284 return nil , err
300285 }
301286
302- cli := o .client
303- if len (o .app .appInstallationClient ) > 0 {
304- i , err := strconv .ParseInt (entitlement .Resource .ParentResourceId .GetResource (), 10 , 64 )
305- if err != nil {
306- return nil , err
307- }
308- var ok bool
309- cli , ok = o .app .appInstallationClient [i ]
310- if ! ok {
311- return nil , fmt .Errorf ("organization: %d doesn't exist" , i )
312- }
287+ cli , err := getClient (o .client , o .app , entitlement .Resource .ParentResourceId .GetResource ())
288+ if err != nil {
289+ return nil , err
313290 }
314291
315292 user , _ , err := cli .Users .GetByID (ctx , userId )
@@ -372,18 +349,11 @@ func (o *teamResourceType) Revoke(ctx context.Context, grant *v2.Grant) (annotat
372349 return nil , err
373350 }
374351
375- cli := o .client
376- if len (o .app .appInstallationClient ) > 0 {
377- i , err := strconv .ParseInt (grant .GetEntitlement ().GetResource ().GetParentResourceId ().GetResource (), 10 , 64 )
378- if err != nil {
379- return nil , err
380- }
381- var ok bool
382- cli , ok = o .app .appInstallationClient [i ]
383- if ! ok {
384- return nil , fmt .Errorf ("organization: %d doesn't exist" , i )
385- }
352+ cli , err := getClient (o .client , o .app , grant .GetEntitlement ().GetResource ().GetParentResourceId ().GetResource ())
353+ if err != nil {
354+ return nil , err
386355 }
356+
387357 user , _ , err := cli .Users .GetByID (ctx , userId )
388358 if err != nil {
389359 return nil , fmt .Errorf ("github-connectorv2: failed to get user %d, err: %w" , userId , err )
0 commit comments