aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-11-13 17:10:25 -0500
committerUnknwon <u@gogs.io>2015-11-13 17:10:25 -0500
commit1d57f0d64fcd9aec16b4003d5664f31ea748da03 (patch)
treea369a2581ffc57633c1813dee8ff29d2655fdeb0 /models
parent1559bd58e7dee6927d31e1aaf1b6ebfc0ffd59dc (diff)
downloadgitea-1d57f0d64fcd9aec16b4003d5664f31ea748da03.tar.gz
gitea-1d57f0d64fcd9aec16b4003d5664f31ea748da03.zip
Show custom avatars in commits
Diffstat (limited to 'models')
-rw-r--r--models/action.go46
-rw-r--r--models/update.go9
-rw-r--r--models/user.go2
3 files changed, 48 insertions, 9 deletions
diff --git a/models/action.go b/models/action.go
index 536476d7e1..bb15d4a3d8 100644
--- a/models/action.go
+++ b/models/action.go
@@ -208,8 +208,48 @@ func issueIndexTrimRight(c rune) bool {
return !unicode.IsDigit(c)
}
+type PushCommit struct {
+ Sha1 string
+ Message string
+ AuthorEmail string
+ AuthorName string
+}
+
+type PushCommits struct {
+ Len int
+ Commits []*PushCommit
+ CompareUrl string
+
+ avatars map[string]string
+}
+
+func NewPushCommits() *PushCommits {
+ return &PushCommits{
+ avatars: make(map[string]string),
+ }
+}
+
+// AvatarLink tries to match user in database with e-mail
+// in order to show custom avatar, and falls back to general avatar link.
+func (push *PushCommits) AvatarLink(email string) string {
+ _, ok := push.avatars[email]
+ if !ok {
+ u, err := GetUserByEmail(email)
+ if err != nil {
+ push.avatars[email] = base.AvatarLink(email)
+ if !IsErrUserNotExist(err) {
+ log.Error(4, "GetUserByEmail: %v", err)
+ }
+ } else {
+ push.avatars[email] = u.AvatarLink()
+ }
+ }
+
+ return push.avatars[email]
+}
+
// updateIssuesCommit checks if issues are manipulated by commit message.
-func updateIssuesCommit(u *User, repo *Repository, repoUserName, repoName string, commits []*base.PushCommit) error {
+func updateIssuesCommit(u *User, repo *Repository, repoUserName, repoName string, commits []*PushCommit) error {
// Commits are appended in the reverse order.
for i := len(commits) - 1; i >= 0; i-- {
c := commits[i]
@@ -343,7 +383,7 @@ func CommitRepoAction(
repoID int64,
repoUserName, repoName string,
refFullName string,
- commit *base.PushCommits,
+ commit *PushCommits,
oldCommitID string, newCommitID string) error {
u, err := GetUserByID(userID)
@@ -369,7 +409,7 @@ func CommitRepoAction(
// Check it's tag push or branch.
if strings.HasPrefix(refFullName, "refs/tags/") {
opType = PUSH_TAG
- commit = &base.PushCommits{}
+ commit = &PushCommits{}
} else {
// if not the first commit, set the compareUrl
if !strings.HasPrefix(oldCommitID, "0000000") {
diff --git a/models/update.go b/models/update.go
index 7992313a80..14e56ce813 100644
--- a/models/update.go
+++ b/models/update.go
@@ -10,7 +10,6 @@ import (
"os/exec"
"strings"
- "github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log"
)
@@ -100,7 +99,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName
actEmail = cmt.Committer.Email
}
- commit := &base.PushCommits{}
+ commit := &PushCommits{}
if err = CommitRepoAction(userID, user.Id, userName, actEmail,
repo.ID, repoUserName, repoName, refName, commit, oldCommitID, newCommitID); err != nil {
@@ -133,7 +132,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName
}
// Push commits.
- commits := make([]*base.PushCommit, 0)
+ commits := make([]*PushCommit, 0)
var actEmail string
for e := l.Front(); e != nil; e = e.Next() {
commit := e.Value.(*git.Commit)
@@ -141,7 +140,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName
actEmail = commit.Committer.Email
}
commits = append(commits,
- &base.PushCommit{commit.ID.String(),
+ &PushCommit{commit.ID.String(),
commit.Message(),
commit.Author.Email,
commit.Author.Name,
@@ -149,7 +148,7 @@ func Update(refName, oldCommitID, newCommitID, userName, repoUserName, repoName
}
if err = CommitRepoAction(userID, user.Id, userName, actEmail,
- repo.ID, repoUserName, repoName, refName, &base.PushCommits{l.Len(), commits, ""}, oldCommitID, newCommitID); err != nil {
+ repo.ID, repoUserName, repoName, refName, &PushCommits{l.Len(), commits, "", nil}, oldCommitID, newCommitID); err != nil {
return fmt.Errorf("runUpdate.models.CommitRepoAction: %s/%s:%v", repoUserName, repoName, err)
}
return nil
diff --git a/models/user.go b/models/user.go
index 628a50f720..5aaf630f4a 100644
--- a/models/user.go
+++ b/models/user.go
@@ -991,7 +991,7 @@ func GetUserByEmail(email string) (*User, error) {
return GetUserByID(emailAddress.UID)
}
- return nil, ErrUserNotExist{0, "email"}
+ return nil, ErrUserNotExist{0, email}
}
// SearchUserByName returns given number of users whose name contains keyword.