summaryrefslogtreecommitdiffstats
path: root/models/action.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/action.go')
-rw-r--r--models/action.go66
1 files changed, 53 insertions, 13 deletions
diff --git a/models/action.go b/models/action.go
index 9050be22a6..cde0fb080e 100644
--- a/models/action.go
+++ b/models/action.go
@@ -194,6 +194,10 @@ func (a *Action) GetRepoLink() string {
// GetCommentLink returns link to action comment.
func (a *Action) GetCommentLink() string {
+ return a.getCommentLink(x)
+}
+
+func (a *Action) getCommentLink(e Engine) string {
if a == nil {
return "#"
}
@@ -213,11 +217,15 @@ func (a *Action) GetCommentLink() string {
return "#"
}
- issue, err := GetIssueByID(issueID)
+ issue, err := getIssueByID(e, issueID)
if err != nil {
return "#"
}
+ if err = issue.loadRepo(e); err != nil {
+ return "#"
+ }
+
return issue.HTMLURL()
}
@@ -330,13 +338,15 @@ type PushCommits struct {
Commits []*PushCommit
CompareURL string
- avatars map[string]string
+ avatars map[string]string
+ emailUsers map[string]*User
}
// NewPushCommits creates a new PushCommits object.
func NewPushCommits() *PushCommits {
return &PushCommits{
- avatars: make(map[string]string),
+ avatars: make(map[string]string),
+ emailUsers: make(map[string]*User),
}
}
@@ -344,16 +354,34 @@ func NewPushCommits() *PushCommits {
// api.PayloadCommit format.
func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit {
commits := make([]*api.PayloadCommit, len(pc.Commits))
+
+ if pc.emailUsers == nil {
+ pc.emailUsers = make(map[string]*User)
+ }
+ var err error
for i, commit := range pc.Commits {
authorUsername := ""
- author, err := GetUserByEmail(commit.AuthorEmail)
- if err == nil {
+ author, ok := pc.emailUsers[commit.AuthorEmail]
+ if !ok {
+ author, err = GetUserByEmail(commit.AuthorEmail)
+ if err == nil {
+ authorUsername = author.Name
+ pc.emailUsers[commit.AuthorEmail] = author
+ }
+ } else {
authorUsername = author.Name
}
+
committerUsername := ""
- committer, err := GetUserByEmail(commit.CommitterEmail)
- if err == nil {
- // TODO: check errors other than email not found.
+ committer, ok := pc.emailUsers[commit.CommitterEmail]
+ if !ok {
+ committer, err = GetUserByEmail(commit.CommitterEmail)
+ if err == nil {
+ // TODO: check errors other than email not found.
+ committerUsername = committer.Name
+ pc.emailUsers[commit.CommitterEmail] = committer
+ }
+ } else {
committerUsername = committer.Name
}
commits[i] = &api.PayloadCommit{
@@ -379,18 +407,28 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoLink string) []*api.PayloadCommit
// AvatarLink tries to match user in database with e-mail
// in order to show custom avatar, and falls back to general avatar link.
func (pc *PushCommits) AvatarLink(email string) string {
- _, ok := pc.avatars[email]
+ avatar, ok := pc.avatars[email]
+ if ok {
+ return avatar
+ }
+
+ u, ok := pc.emailUsers[email]
if !ok {
- u, err := GetUserByEmail(email)
+ var err error
+ u, err = GetUserByEmail(email)
if err != nil {
pc.avatars[email] = base.AvatarLink(email)
if !IsErrUserNotExist(err) {
log.Error(4, "GetUserByEmail: %v", err)
+ return ""
}
} else {
- pc.avatars[email] = u.RelAvatarLink()
+ pc.emailUsers[email] = u
}
}
+ if u != nil {
+ pc.avatars[email] = u.RelAvatarLink()
+ }
return pc.avatars[email]
}
@@ -479,7 +517,8 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
continue
}
- if err = issue.ChangeStatus(doer, repo, true); err != nil {
+ issue.Repo = repo
+ if err = issue.ChangeStatus(doer, true); err != nil {
// Don't return an error when dependencies are open as this would let the push fail
if IsErrDependenciesLeft(err) {
return nil
@@ -504,7 +543,8 @@ func UpdateIssuesCommit(doer *User, repo *Repository, commits []*PushCommit) err
continue
}
- if err = issue.ChangeStatus(doer, repo, false); err != nil {
+ issue.Repo = repo
+ if err = issue.ChangeStatus(doer, false); err != nil {
return err
}
}