diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-10 17:34:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-10 17:34:21 +0800 |
commit | 99d869fa63e07780f1a17d1a9599187b9b689d9b (patch) | |
tree | ecadeba077cf0ae58d0a21f232d280fec60c779a /models/action.go | |
parent | 384c2b342ec01fadb520572666127cb5564e1050 (diff) | |
download | gitea-99d869fa63e07780f1a17d1a9599187b9b689d9b.tar.gz gitea-99d869fa63e07780f1a17d1a9599187b9b689d9b.zip |
Move push commits from models to modules/repository (#9370)
* Move push commits from models to modules/repository
* fix test
* fix test
* fix test
* fix test
* fix test
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'models/action.go')
-rw-r--r-- | models/action.go | 126 |
1 files changed, 0 insertions, 126 deletions
diff --git a/models/action.go b/models/action.go index dd642c6c1f..a7e04a72fd 100644 --- a/models/action.go +++ b/models/action.go @@ -13,10 +13,8 @@ import ( "time" "code.gitea.io/gitea/modules/base" - "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/timeutil" "github.com/unknwon/com" @@ -284,130 +282,6 @@ func (a *Action) GetIssueContent() string { return issue.Content } -// PushCommit represents a commit in a push operation. -type PushCommit struct { - Sha1 string - Message string - AuthorEmail string - AuthorName string - CommitterEmail string - CommitterName string - Timestamp time.Time -} - -// PushCommits represents list of commits in a push operation. -type PushCommits struct { - Len int - Commits []*PushCommit - CompareURL 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), - emailUsers: make(map[string]*User), - } -} - -// ToAPIPayloadCommits converts a PushCommits object to -// api.PayloadCommit format. -func (pc *PushCommits) ToAPIPayloadCommits(repoPath, repoLink string) ([]*api.PayloadCommit, error) { - 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, 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, 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 - } - - fileStatus, err := git.GetCommitFileStatus(repoPath, commit.Sha1) - if err != nil { - return nil, fmt.Errorf("FileStatus [commit_sha1: %s]: %v", commit.Sha1, err) - } - - commits[i] = &api.PayloadCommit{ - ID: commit.Sha1, - Message: commit.Message, - URL: fmt.Sprintf("%s/commit/%s", repoLink, commit.Sha1), - Author: &api.PayloadUser{ - Name: commit.AuthorName, - Email: commit.AuthorEmail, - UserName: authorUsername, - }, - Committer: &api.PayloadUser{ - Name: commit.CommitterName, - Email: commit.CommitterEmail, - UserName: committerUsername, - }, - Added: fileStatus.Added, - Removed: fileStatus.Removed, - Modified: fileStatus.Modified, - Timestamp: commit.Timestamp, - } - } - return commits, nil -} - -// 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 { - if pc.avatars == nil { - pc.avatars = make(map[string]string) - } - avatar, ok := pc.avatars[email] - if ok { - return avatar - } - - u, ok := pc.emailUsers[email] - if !ok { - var err error - u, err = GetUserByEmail(email) - if err != nil { - pc.avatars[email] = base.AvatarLink(email) - if !IsErrUserNotExist(err) { - log.Error("GetUserByEmail: %v", err) - return "" - } - } else { - pc.emailUsers[email] = u - } - } - if u != nil { - pc.avatars[email] = u.RelAvatarLink() - } - - return pc.avatars[email] -} - // GetFeedsOptions options for retrieving feeds type GetFeedsOptions struct { RequestedUser *User |