@@ -3,6 +3,7 @@ package connector
33import (
44 "context"
55 "fmt"
6+ "net/http"
67 "strconv"
78 "strings"
89
@@ -133,6 +134,7 @@ func (o *repositoryResourceType) Grants(
133134 resource * v2.Resource ,
134135 pToken * pagination.Token ,
135136) ([]* v2.Grant , string , annotations.Annotations , error ) {
137+ l := ctxzap .Extract (ctx )
136138 bag , page , err := parsePageToken (pToken .Token , resource .Id )
137139 if err != nil {
138140 return nil , "" , nil , err
@@ -163,6 +165,14 @@ func (o *repositoryResourceType) Grants(
163165 }
164166 users , resp , err := o .client .Repositories .ListCollaborators (ctx , orgName , resource .DisplayName , opts )
165167 if err != nil {
168+ if resp .StatusCode == http .StatusForbidden {
169+ l .Warn ("insufficient access to list collaborators" , zap .String ("repository" , resource .DisplayName ))
170+ pageToken , err := skipGrantsForResourceType (bag )
171+ if err != nil {
172+ return nil , "" , nil , err
173+ }
174+ return nil , pageToken , nil , nil
175+ }
166176 return nil , "" , nil , fmt .Errorf ("github-connector: failed to list repos: %w" , err )
167177 }
168178
@@ -202,6 +212,14 @@ func (o *repositoryResourceType) Grants(
202212 }
203213 teams , resp , err := o .client .Repositories .ListTeams (ctx , orgName , resource .DisplayName , opts )
204214 if err != nil {
215+ if resp .StatusCode == http .StatusForbidden {
216+ l .Warn ("insufficient access to list teams" , zap .String ("repository" , resource .DisplayName ))
217+ pageToken , err := skipGrantsForResourceType (bag )
218+ if err != nil {
219+ return nil , "" , nil , err
220+ }
221+ return nil , pageToken , nil , nil
222+ }
205223 return nil , "" , nil , fmt .Errorf ("github-connector: failed to list repos: %w" , err )
206224 }
207225
@@ -384,3 +402,15 @@ func repositoryBuilder(client *github.Client, orgCache *orgNameCache) *repositor
384402 orgCache : orgCache ,
385403 }
386404}
405+
406+ func skipGrantsForResourceType (bag * pagination.Bag ) (string , error ) {
407+ err := bag .Next ("" )
408+ if err != nil {
409+ return "" , err
410+ }
411+ pageToken , err := bag .Marshal ()
412+ if err != nil {
413+ return "" , err
414+ }
415+ return pageToken , nil
416+ }
0 commit comments