mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-03-25 09:25:49 +00:00
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.
This commit is contained in:
parent
054ea6e082
commit
d831754422
3 changed files with 3 additions and 103 deletions
78
app/repos.go
78
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
<div class="repos">
|
||||
<h2>
|
||||
|
|
@ -40,19 +40,6 @@
|
|||
</div>
|
||||
{{end}}
|
||||
|
||||
{{range .Repos.OrgRepos}}
|
||||
<div class="repos">
|
||||
<h2>
|
||||
<a href="https://github.com/{{.Org.Login}}">{{.Org.Login}}</a>
|
||||
</h2>
|
||||
<ul>
|
||||
{{range .Repos}}
|
||||
{{template "repo" .}}
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{end}}
|
||||
|
||||
{{end}}
|
||||
|
|
|
|||
|
|
@ -114,19 +114,6 @@
|
|||
</div>
|
||||
{{end}}
|
||||
|
||||
{{range .Repos.OrgRepos}}
|
||||
<div class="repos">
|
||||
<h2>
|
||||
<a href="https://github.com/{{.Org.Login}}">
|
||||
<img src="{{.Org.AvatarURL}}" class="avatar">{{.Org.Login}}</a>
|
||||
</h2>
|
||||
<ul>
|
||||
{{range .Repos}}
|
||||
{{template "repo" .}}
|
||||
{{end}}
|
||||
</ul>
|
||||
</div>
|
||||
{{end}}
|
||||
</div>
|
||||
</label>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue