func fetchRepositories()

in resources/services/table.go [39:67]


func fetchRepositories(ghClient *gh.Client) ([]*gh.Repository, error) {
	opts := &gh.RepositoryListByOrgOptions{
		ListOptions: gh.ListOptions{
			PerPage: 100,
		}}

	var allRepos []*gh.Repository
	for {
		repos, resp, err := ghClient.Repositories.ListByOrg(context.Background(), "guardian", opts)
		if err != nil {
			return nil, err
		}

		for _, repo := range repos {
			//we are filtering here to only include repos we care about for OKR purposes.
			//the filters can be removed after we are sure we won't hit the rate limit
			if !*repo.Archived && contains(repo.Topics, "production") {
				allRepos = append(allRepos, repo)
			}
		}

		fmt.Println("Counted ", len(allRepos), " repos so far")
		if resp.NextPage == 0 {
			break
		}
		opts.Page = resp.NextPage
	}
	return allRepos, nil
}