1
0
Fork 0

Sync team members task

This commit is contained in:
Gregory Eremin 2015-03-19 20:33:58 +07:00
parent a37a7ce315
commit 46cf7f600b
1 changed files with 33 additions and 6 deletions

View File

@ -26,7 +26,7 @@ func SyncRepos(token, owner string) {
} }
r.Save() r.Save()
} }
if opt.Page == resp.LastPage { if opt.Page >= resp.LastPage {
break break
} }
} }
@ -96,7 +96,7 @@ func SyncUserOrgs(token string) (err error) {
go SyncOrgMembers(token, o) go SyncOrgMembers(token, o)
o.Save() o.Save()
} }
if opt.Page == resp.LastPage { if opt.Page >= resp.LastPage {
break break
} }
} }
@ -126,9 +126,10 @@ func SyncOrgTeams(token string, org *db.Org) (err error) {
Permission: *team.Permission, Permission: *team.Permission,
OrgID: org.ID, OrgID: org.ID,
} }
go SyncTeamMembers(token, t)
t.Save() t.Save()
} }
if opt.Page == resp.LastPage { if opt.Page >= resp.LastPage {
break break
} }
} }
@ -137,12 +138,11 @@ func SyncOrgTeams(token string, org *db.Org) (err error) {
} }
func SyncOrgMembers(token string, org *db.Org) (err error) { func SyncOrgMembers(token string, org *db.Org) (err error) {
defer report("SyncOrgTeams", time.Now()) defer report("SyncOrgMembers", time.Now())
client := newGithubClient(token) client := newGithubClient(token)
opt := &github.ListMembersOptions{ListOptions: github.ListOptions{PerPage: 100}} opt := &github.ListMembersOptions{ListOptions: github.ListOptions{PerPage: 100}}
var ids = []uint64{} var ids = []uint64{}
for { for {
opt.Page++ opt.Page++
var users []github.User var users []github.User
@ -169,7 +169,7 @@ func SyncOrgMembers(token string, org *db.Org) (err error) {
u.Save() u.Save()
ids = append(ids, u.ID) ids = append(ids, u.ID)
} }
if opt.Page == resp.LastPage { if opt.Page >= resp.LastPage {
break break
} }
} }
@ -177,3 +177,30 @@ func SyncOrgMembers(token string, org *db.Org) (err error) {
return return
} }
func SyncTeamMembers(token string, team *db.Team) (err error) {
defer report("SyncTeamMembers", time.Now())
client := newGithubClient(token)
opt := &github.ListOptions{PerPage: 100}
var ids = []uint64{}
for {
opt.Page++
var users []github.User
var resp *github.Response
if users, resp, err = client.Organizations.ListTeamMembers(int(team.ID), opt); err != nil {
return
}
saveResponseMeta(token, resp)
for _, user := range users {
ids = append(ids, uint64(*user.ID))
}
if opt.Page >= resp.LastPage {
break
}
}
db.SaveTeamMembers(team.OrgID, team.ID, ids)
return
}