1
0
Fork 0

Fix fetching multiple pages in sync repo task

This commit is contained in:
Gregory Eremin 2015-03-19 19:55:01 +07:00
parent f8d7f814d0
commit 782769861a
1 changed files with 11 additions and 9 deletions

View File

@ -10,9 +10,7 @@ import (
func SyncRepos(token, owner string) { func SyncRepos(token, owner string) {
defer report("SyncRepos", time.Now()) defer report("SyncRepos", time.Now())
client := newGithubClient(token) client := newGithubClient(token)
opt := &github.RepositoryListByOrgOptions{ opt := &github.RepositoryListByOrgOptions{ListOptions: github.ListOptions{PerPage: 100}}
ListOptions: github.ListOptions{},
}
for { for {
opt.Page++ opt.Page++
@ -28,7 +26,7 @@ func SyncRepos(token, owner string) {
} }
r.Save() r.Save()
} }
if len(repos) < 30 { if opt.Page == resp.LastPage {
break break
} }
} }
@ -37,6 +35,7 @@ func SyncRepos(token, owner string) {
func SyncContrib(token, owner, repo string) { func SyncContrib(token, owner, repo string) {
defer report("SyncContrib", time.Now()) defer report("SyncContrib", time.Now())
client := newGithubClient(token) client := newGithubClient(token)
contribs, resp, err := client.Repositories.ListContributorsStats(owner, repo) contribs, resp, err := client.Repositories.ListContributorsStats(owner, repo)
saveResponseMeta(token, resp) saveResponseMeta(token, resp)
if err != nil { if err != nil {
@ -46,22 +45,25 @@ func SyncContrib(token, owner, repo string) {
panic(err) panic(err)
} }
for _, c := range contribs { for _, contrib := range contribs {
for _, week := range c.Weeks { for _, week := range contrib.Weeks {
if *week.Commits == 0 { if *week.Commits == 0 {
continue continue
} }
contrib := &db.Contrib{ c := &db.Contrib{
Week: uint64(week.Week.Time.Unix()), Week: uint64(week.Week.Time.Unix()),
Author: *c.Author.Login, Author: *contrib.Author.Login,
Owner: owner, Owner: owner,
Repo: repo, Repo: repo,
Commits: uint64(*week.Commits), Commits: uint64(*week.Commits),
Additions: uint64(*week.Additions), Additions: uint64(*week.Additions),
Deletions: uint64(*week.Deletions), Deletions: uint64(*week.Deletions),
} }
contrib.Save() c.Save()
}
}
}
func SyncUserOrgs(token string) (err error) { func SyncUserOrgs(token string) (err error) {
defer report("SyncUserOrgs", time.Now()) defer report("SyncUserOrgs", time.Now())