commit
c064f37867
6 changed files with 48 additions and 5 deletions
|
@ -48,6 +48,7 @@ type Project struct {
|
|||
SshRepoUrl string `json:"ssh_url_to_repo"`
|
||||
HttpRepoUrl string `json:"http_url_to_repo"`
|
||||
Url string `json:"web_url"`
|
||||
AvatarUrl string `json:"avatar_url"`
|
||||
Permissions *Permissions `json:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -145,6 +145,12 @@ func (g *Gitlab) Repo(u *model.User, owner, name string) (*model.Repo, error) {
|
|||
repo.Clone = repo_.HttpRepoUrl
|
||||
repo.Branch = "master"
|
||||
|
||||
repo.Avatar = repo_.AvatarUrl
|
||||
|
||||
if len(repo.Avatar) != 0 && !strings.HasPrefix(repo.Avatar, "http") {
|
||||
repo.Avatar = fmt.Sprintf("%s/%s", g.URL, repo.Avatar)
|
||||
}
|
||||
|
||||
if repo_.DefaultBranch != "" {
|
||||
repo.Branch = repo_.DefaultBranch
|
||||
}
|
||||
|
@ -173,15 +179,20 @@ func (g *Gitlab) Repos(u *model.User) ([]*model.RepoLite, error) {
|
|||
var parts = strings.Split(repo.PathWithNamespace, "/")
|
||||
var owner = parts[0]
|
||||
var name = parts[1]
|
||||
var avatar = repo.AvatarUrl
|
||||
|
||||
if len(avatar) != 0 && !strings.HasPrefix(avatar, "http") {
|
||||
avatar = fmt.Sprintf("%s/%s", g.URL, avatar)
|
||||
}
|
||||
|
||||
repos = append(repos, &model.RepoLite{
|
||||
Owner: owner,
|
||||
Name: name,
|
||||
FullName: repo.PathWithNamespace,
|
||||
Avatar: avatar,
|
||||
})
|
||||
|
||||
// TODO: add repo.AvatarUrl
|
||||
}
|
||||
|
||||
return repos, err
|
||||
}
|
||||
|
||||
|
@ -201,7 +212,7 @@ func (g *Gitlab) Perm(u *model.User, owner, name string) (*model.Perm, error) {
|
|||
|
||||
// repo owner is granted full access
|
||||
if repo.Owner != nil && repo.Owner.Username == u.Login {
|
||||
return &model.Perm{true, true, true}, nil
|
||||
return &model.Perm{true, true, true}, nil
|
||||
}
|
||||
|
||||
// check permission for current user
|
||||
|
@ -361,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
|
||||
|
||||
|
@ -406,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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
BIN
static/images/dummy.png
Normal file
BIN
static/images/dummy.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -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}
|
||||
|
|
|
@ -20,7 +20,10 @@ block content
|
|||
div.col-sm-4
|
||||
a.card[href="/"+$repo.FullName]
|
||||
div.card-header
|
||||
img.avatar[src=$repo.Avatar]
|
||||
if $repo.Avatar != ""
|
||||
img.avatar[src=$repo.Avatar]
|
||||
else
|
||||
img.avatar[src="/static/images/dummy.png"]
|
||||
div.card-block
|
||||
h3.login #{$repo.Name}
|
||||
div.full_name.hidden #{$repo.FullName}
|
||||
|
|
Loading…
Reference in a new issue