2015-03-11 12:10:29 +00:00
|
|
|
package task
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/go-github/github"
|
|
|
|
"github.com/localhots/empact/db"
|
|
|
|
)
|
|
|
|
|
|
|
|
func FetchUserInfo(token, login string) (u *db.User, err error) {
|
|
|
|
defer report("FetchUserInfo", time.Now())
|
|
|
|
|
|
|
|
client := newGithubClient(token)
|
|
|
|
var user *github.User
|
|
|
|
var resp *github.Response
|
|
|
|
if user, resp, err = client.Users.Get(login); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
saveResponseMeta(token, resp)
|
|
|
|
|
2015-03-14 17:01:48 +00:00
|
|
|
name := ""
|
|
|
|
if n := user.Name; n != nil {
|
|
|
|
name = *user.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
avatarURL := ""
|
|
|
|
if url := user.AvatarURL; url != nil {
|
|
|
|
avatarURL = *user.AvatarURL
|
|
|
|
}
|
|
|
|
|
2015-03-11 12:10:29 +00:00
|
|
|
u = &db.User{
|
|
|
|
Login: *user.Login,
|
2015-03-14 17:01:48 +00:00
|
|
|
Name: name,
|
2015-03-11 12:10:29 +00:00
|
|
|
ID: uint64(*user.ID),
|
2015-03-14 17:01:48 +00:00
|
|
|
AvatarURL: avatarURL,
|
2015-03-11 12:10:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|