From d831754422171f9228badca97df9e720bbf50386 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Tue, 18 Aug 2015 22:13:38 -0700 Subject: [PATCH] Stop querying for the organization list. The changes to the repositories and organization APIs are live (https://developer.github.com/changes/2015-06-24-breaking-changes-to-organization-permissions-are-now-official/) and thus the scopes used for the public repositories only option are no longer sufficient to list organizations. However, it's no longer necessary to do that in the first place, since the user repository list now includes repos from organizations. --- app/repos.go | 78 +--------------------------------- app/templates/repos-admin.html | 15 +------ app/templates/settings.html | 13 ------ 3 files changed, 3 insertions(+), 103 deletions(-) diff --git a/app/repos.go b/app/repos.go index 02a9e04..d1af76b 100644 --- a/app/repos.go +++ b/app/repos.go @@ -163,7 +163,6 @@ type Repos struct { AllRepos []*Repo UserRepos []*Repo OtherUserRepos []*UserRepos - OrgRepos []*OrgRepos OldestVintage time.Time } @@ -180,14 +179,6 @@ func (repos *Repos) Redact() { *repo.FullName = "redacted/redacted" } } - for _, orgRepos := range repos.OrgRepos { - *orgRepos.Org.Login = "redacted" - *orgRepos.Org.AvatarURL = "https://redacted" - for _, repo := range orgRepos.Repos { - *repo.HTMLURL = "https://redacted" - *repo.FullName = "redacted/redacted" - } - } } type Repo struct { @@ -233,11 +224,6 @@ type UserRepos struct { Repos []*Repo } -type OrgRepos struct { - Org *github.Organization - Repos []*Repo -} - func getRepos(c appengine.Context, githubClient *github.Client, account *Account, user *github.User) (*Repos, error) { clientUserRepos := make([]github.Repository, 0) page := 1 @@ -266,9 +252,7 @@ func getRepos(c appengine.Context, githubClient *github.Client, account *Account repos := &Repos{} repos.UserRepos = make([]*Repo, 0, len(clientUserRepos)) repos.OtherUserRepos = make([]*UserRepos, 0) - allRepoNames := make(map[string]int) for i := range clientUserRepos { - allRepoNames[*clientUserRepos[i].FullName] = 1 ownerID := *clientUserRepos[i].Owner.ID if ownerID == *user.ID { repos.UserRepos = append(repos.UserRepos, newRepo(&clientUserRepos[i], account)) @@ -291,71 +275,13 @@ func getRepos(c appengine.Context, githubClient *github.Client, account *Account } } - orgs, _, err := githubClient.Organizations.List( - "", - &github.ListOptions{ - // Don't bother with pagination for the organization list, the user - // is unlikely to have that many. - PerPage: 100, - }) - if err != nil { - return nil, err - } - - repos.OrgRepos = make([]*OrgRepos, 0, len(orgs)) - for i := range orgs { - org := &orgs[i] - clientOrgRepos := make([]github.Repository, 0) - page := 1 - for { - pageClientOrgRepos, response, err := githubClient.Repositories.ListByOrg( - *org.Login, - &github.RepositoryListByOrgOptions{ - Type: "member", - ListOptions: github.ListOptions{ - Page: page, - PerPage: 100, - }, - }) - if err != nil { - return nil, err - } - clientOrgRepos = append(clientOrgRepos, pageClientOrgRepos...) - if response.NextPage == 0 { - break - } - page = response.NextPage - } - orgRepos := make([]*Repo, 0, len(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)) - } - repos.OrgRepos = append(repos.OrgRepos, &OrgRepos{org, orgRepos}) - } - - repos.AllRepos = make([]*Repo, 0, len(allRepoNames)) + repos.AllRepos = make([]*Repo, 0, len(clientUserRepos)) repos.AllRepos = append(repos.AllRepos, repos.UserRepos...) for _, userRepos := range repos.OtherUserRepos { repos.AllRepos = append(repos.AllRepos, userRepos.Repos...) } - for _, org := range repos.OrgRepos { - repos.AllRepos = append(repos.AllRepos, org.Repos...) - } - err = fillVintages(c, user, repos.AllRepos) + err := fillVintages(c, user, repos.AllRepos) if err != nil { return nil, err } diff --git a/app/templates/repos-admin.html b/app/templates/repos-admin.html index ee2cc20..114cb23 100644 --- a/app/templates/repos-admin.html +++ b/app/templates/repos-admin.html @@ -13,7 +13,7 @@ {{if .ReposError}} {{.ReposError}} {{else}} - {{len .Repos.AllRepos}} from {{len .Repos.OtherUserRepos}} other users and {{len .Repos.OrgRepos}} organizations + {{len .Repos.AllRepos}} from {{len .Repos.OtherUserRepos}} other users

@@ -40,19 +40,6 @@

{{end}} - {{range .Repos.OrgRepos}} -
-

- {{.Org.Login}} -

- -
- {{end}} - {{end}} {{end}} diff --git a/app/templates/settings.html b/app/templates/settings.html index a68ef4b..5328998 100644 --- a/app/templates/settings.html +++ b/app/templates/settings.html @@ -114,19 +114,6 @@ {{end}} - {{range .Repos.OrgRepos}} -
-

- - {{.Org.Login}} -

- -
- {{end}}