MCPcopy Index your code
hub / github.com/crashappsec/github-analyzer / GetRepositories

Method GetRepositories

pkg/github/org/org.go:316–375  ·  view source on GitHub ↗

GetRepositories returns the repositories for a given org. Upon first call, it lazily updates the Organization with the repository information

(ctx context.Context)

Source from the content-addressed store, hash-verified

314// GetRepositories returns the repositories for a given org. Upon first call,
315// it lazily updates the Organization with the repository information
316func (org *Organization) GetRepositories(ctx context.Context) (
317 map[types.RepoName]repo.Repository, error) {
318
319 if len(org.Repositories) > 0 {
320 return org.Repositories, nil
321 }
322
323 log.Logger.Debugf("Fetching repositories for %s", *org.info.Login)
324 opt := &github.RepositoryListByOrgOptions{
325 ListOptions: github.ListOptions{PerPage: org.paginationSize},
326 }
327 ghRepos, err := utils.GetPaginatedResult(
328 ctx,
329 org.backoff,
330 &opt.ListOptions,
331 func(opts *github.ListOptions) ([]*github.Repository, *github.Response, error) {
332 return org.client.Repositories.ListByOrg(
333 ctx,
334 *org.info.Login,
335 opt,
336 )
337 },
338 func(ghRepositories []*github.Repository) []repo.Repository {
339 var repos []repo.Repository
340 for _, ghRepository := range ghRepositories {
341 // ghRepository has incomplete information at this stage wrt to Org
342 ghRepo, _, err := org.client.Repositories.GetByID(
343 ctx,
344 *ghRepository.ID,
345 )
346 if err != nil {
347 log.Logger.Error(err)
348 continue
349 }
350 r, err := repo.NewRepository(
351 ctx,
352 org.client,
353 org.backoff,
354 ghRepo,
355 )
356 if err != nil {
357 log.Logger.Error(err)
358 continue
359 }
360 repos = append(repos, *r)
361 }
362 return repos
363 },
364 )
365 if err != nil {
366 log.Logger.Error(err)
367 }
368
369 repositories := make(map[types.RepoName]repo.Repository, len(ghRepos))
370 for _, r := range ghRepos {
371 repositories[types.RepoName(*r.CoreStats.Name)] = r
372 }
373 org.Repositories = repositories

Callers 1

Calls 2

GetPaginatedResultFunction · 0.92
NewRepositoryFunction · 0.92

Tested by

no test coverage detected