This commit is contained in:
Mihai Parparita 2015-02-07 14:38:33 -08:00
parent 741e7e0a2f
commit 054ea6e082

View file

@ -266,8 +266,9 @@ func getRepos(c appengine.Context, githubClient *github.Client, account *Account
repos := &Repos{} repos := &Repos{}
repos.UserRepos = make([]*Repo, 0, len(clientUserRepos)) repos.UserRepos = make([]*Repo, 0, len(clientUserRepos))
repos.OtherUserRepos = make([]*UserRepos, 0) repos.OtherUserRepos = make([]*UserRepos, 0)
allRepoCount := len(clientUserRepos) allRepoNames := make(map[string]int)
for i := range clientUserRepos { for i := range clientUserRepos {
allRepoNames[*clientUserRepos[i].FullName] = 1
ownerID := *clientUserRepos[i].Owner.ID ownerID := *clientUserRepos[i].Owner.ID
if ownerID == *user.ID { if ownerID == *user.ID {
repos.UserRepos = append(repos.UserRepos, newRepo(&clientUserRepos[i], account)) repos.UserRepos = append(repos.UserRepos, newRepo(&clientUserRepos[i], account))
@ -326,14 +327,26 @@ func getRepos(c appengine.Context, githubClient *github.Client, account *Account
page = response.NextPage page = response.NextPage
} }
orgRepos := make([]*Repo, 0, len(clientOrgRepos)) orgRepos := make([]*Repo, 0, len(clientOrgRepos))
allRepoCount += len(clientOrgRepos)
for j := range clientOrgRepos { for j := range clientOrgRepos {
// Due to https://developer.github.com/changes/2014-12-08-
// organization-permissions-api-preview/ we will start getting
// organization repos in the user repos response above. Make sure
// we don't list repositories twice.
// TODO: Once that change is deployed, we should be able to stop
// querying organization repos altogether.
_, ok := allRepoNames[*clientOrgRepos[j].FullName]
if ok {
c.Infof("Already had repo %s, not adding",
*clientOrgRepos[j].FullName)
continue
}
allRepoNames[*clientOrgRepos[j].FullName] = 1
orgRepos = append(orgRepos, newRepo(&clientOrgRepos[j], account)) orgRepos = append(orgRepos, newRepo(&clientOrgRepos[j], account))
} }
repos.OrgRepos = append(repos.OrgRepos, &OrgRepos{org, orgRepos}) repos.OrgRepos = append(repos.OrgRepos, &OrgRepos{org, orgRepos})
} }
repos.AllRepos = make([]*Repo, 0, allRepoCount) repos.AllRepos = make([]*Repo, 0, len(allRepoNames))
repos.AllRepos = append(repos.AllRepos, repos.UserRepos...) repos.AllRepos = append(repos.AllRepos, repos.UserRepos...)
for _, userRepos := range repos.OtherUserRepos { for _, userRepos := range repos.OtherUserRepos {
repos.AllRepos = append(repos.AllRepos, userRepos.Repos...) repos.AllRepos = append(repos.AllRepos, userRepos.Repos...)