1
0
Fork 0
empact/task/user.go

40 lines
692 B
Go

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
}
u = &db.User{
Login: *user.Login,
Name: name,
ID: uint64(*user.ID),
AvatarURL: avatarURL,
}
return
}