Committer avatar

This commit is contained in:
Kirilll Zaycev 2016-02-01 02:49:52 +03:00
parent 193d524493
commit fbf36458f1
3 changed files with 29 additions and 1 deletions

View file

@ -372,6 +372,10 @@ func mergeRequest(parsed *client.HookPayload, req *http.Request) (*model.Repo, *
build.Author = parsed.ObjectAttributes.LastCommit.Author.Name
build.Email = parsed.ObjectAttributes.LastCommit.Author.Email
if len(build.Email) != 0 {
build.Avatar = GetUserAvatar(build.Email)
}
build.Title = parsed.ObjectAttributes.Title
build.Link = parsed.ObjectAttributes.Url
@ -417,6 +421,9 @@ func push(parsed *client.HookPayload, req *http.Request) (*model.Repo, *model.Bu
case head.Author != nil:
build.Email = head.Author.Email
build.Author = parsed.UserName
if len(build.Email) != 0 {
build.Avatar = GetUserAvatar(build.Email)
}
case head.Author == nil:
build.Author = parsed.UserName
}

View file

@ -1,6 +1,8 @@
package gitlab
import (
"crypto/md5"
"encoding/hex"
"fmt"
"net/url"
"strconv"
@ -8,6 +10,10 @@ import (
"github.com/drone/drone/remote/gitlab/client"
)
const (
gravatarBase = "https://www.gravatar.com/avatar"
)
// NewClient is a helper function that returns a new GitHub
// client using the provided OAuth token.
func NewClient(url, accessToken string, skipVerify bool) *client.Client {
@ -79,6 +85,18 @@ func ns(owner, name string) string {
return fmt.Sprintf("%s%%2F%s", owner, name)
}
func GetUserAvatar(email string) string {
hasher := md5.New()
hasher.Write([]byte(email))
return fmt.Sprintf(
"%s/%v.jpg?s=%s",
gravatarBase,
hex.EncodeToString(hasher.Sum(nil)),
"128",
)
}
func GetUserEmail(c *client.Client, defaultURL string) (*client.Client, error) {
return c, nil
}

View file

@ -32,7 +32,10 @@ block content
each $build in $group.Builds
a.card[href=$repo.Name+"/"+$build.Number][data-build=$build.Number]
div.card-header
img[src=$build.Avatar]
if $build.Avatar != ""
img[src=$build.Avatar]
else
img[src="/static/images/dummy.png"]
div.card-block
div
div.status[class=$build.Status] #{$build.Status}