1
0
Fork 0
empact/task/user.go

40 lines
692 B
Go
Raw Normal View History

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)
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,
Name: name,
2015-03-11 12:10:29 +00:00
ID: uint64(*user.ID),
AvatarURL: avatarURL,
2015-03-11 12:10:29 +00:00
}
return
}