Sync user orgs task
This commit is contained in:
parent
6bb0de0c78
commit
f8d7f814d0
39
task/sync.go
39
task/sync.go
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
task/user.go
22
task/user.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue