Fetch user orgs task
This commit is contained in:
parent
6d1e181db4
commit
a284401d3c
|
@ -5,9 +5,9 @@ import (
|
|||
)
|
||||
|
||||
type Org struct {
|
||||
GithubID uint64 `json:"github_id"`
|
||||
Login string `json:"login"`
|
||||
Descr string `json:"descr"`
|
||||
ID uint64 `json:"id"`
|
||||
Company string `json:"company"`
|
||||
AvatarURL string `json:"avatar_url"`
|
||||
}
|
||||
|
||||
|
|
22
task/user.go
22
task/user.go
|
@ -37,3 +37,25 @@ 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