1
0
Fork 0

Sync user orgs task

This commit is contained in:
Gregory Eremin 2015-03-19 19:51:20 +07:00
parent 6bb0de0c78
commit f8d7f814d0
2 changed files with 39 additions and 22 deletions

View File

@ -62,6 +62,45 @@ func SyncContrib(token, owner, repo string) {
Deletions: uint64(*week.Deletions),
}
contrib.Save()
func SyncUserOrgs(token string) (err error) {
defer report("SyncUserOrgs", time.Now())
client := newGithubClient(token)
opt := &github.ListOptions{PerPage: 100}
for {
var orgs []github.Organization
var resp *github.Response
if orgs, resp, err = client.Organizations.List("", opt); err != nil {
return
}
saveResponseMeta(token, resp)
for _, org := range orgs {
var company, avatarURL string
if org.Company != nil {
company = *org.Company
}
if org.AvatarURL != nil {
avatarURL = *org.AvatarURL
}
o := &db.Org{
ID: uint64(*org.ID),
Login: *org.Login,
Company: company,
AvatarURL: avatarURL,
}
go SyncOrgTeams(token, o)
go SyncOrgMembers(token, o)
o.Save()
}
if opt.Page == resp.LastPage {
break
}
}
return
}
}
}
}

View File

@ -37,25 +37,3 @@ func FetchUserInfo(token, login string) (u *db.User, err error) {
return
}
func FetchUserOrgs(token string) (orgs []*db.Org, err error) {
client := newGithubClient(token)
var ghorgs []github.Organization
var resp *github.Response
if ghorgs, resp, err = client.Organizations.List("", nil); err != nil {
return
}
saveResponseMeta(token, resp)
for _, ghorg := range ghorgs {
org := &db.Org{
GithubID: uint64(*ghorg.ID),
Login: *ghorg.Login,
Company: *ghorg.Company,
AvatarURL: *ghorg.AvatarURL,
}
orgs = append(orgs, org)
}
return
}