forked from NYANDEV/forgejo
Move user related model into models/user (#17781)
* Move user related model into models/user * Fix lint for windows * Fix windows lint * Fix windows lint * Move some tests in models * Merge
This commit is contained in:
parent
4e7ca946da
commit
a666829a37
345 changed files with 4230 additions and 3813 deletions
|
@ -9,8 +9,8 @@ import (
|
|||
"net/url"
|
||||
"time"
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/models/avatars"
|
||||
user_model "code.gitea.io/gitea/models/user"
|
||||
"code.gitea.io/gitea/modules/git"
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
api "code.gitea.io/gitea/modules/structs"
|
||||
|
@ -35,14 +35,14 @@ type PushCommits struct {
|
|||
Len int
|
||||
|
||||
avatars map[string]string
|
||||
emailUsers map[string]*models.User
|
||||
emailUsers map[string]*user_model.User
|
||||
}
|
||||
|
||||
// NewPushCommits creates a new PushCommits object.
|
||||
func NewPushCommits() *PushCommits {
|
||||
return &PushCommits{
|
||||
avatars: make(map[string]string),
|
||||
emailUsers: make(map[string]*models.User),
|
||||
emailUsers: make(map[string]*user_model.User),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,7 +52,7 @@ func (pc *PushCommits) toAPIPayloadCommit(repoPath, repoLink string, commit *Pus
|
|||
authorUsername := ""
|
||||
author, ok := pc.emailUsers[commit.AuthorEmail]
|
||||
if !ok {
|
||||
author, err = models.GetUserByEmail(commit.AuthorEmail)
|
||||
author, err = user_model.GetUserByEmail(commit.AuthorEmail)
|
||||
if err == nil {
|
||||
authorUsername = author.Name
|
||||
pc.emailUsers[commit.AuthorEmail] = author
|
||||
|
@ -64,7 +64,7 @@ func (pc *PushCommits) toAPIPayloadCommit(repoPath, repoLink string, commit *Pus
|
|||
committerUsername := ""
|
||||
committer, ok := pc.emailUsers[commit.CommitterEmail]
|
||||
if !ok {
|
||||
committer, err = models.GetUserByEmail(commit.CommitterEmail)
|
||||
committer, err = user_model.GetUserByEmail(commit.CommitterEmail)
|
||||
if err == nil {
|
||||
// TODO: check errors other than email not found.
|
||||
committerUsername = committer.Name
|
||||
|
@ -107,7 +107,7 @@ func (pc *PushCommits) ToAPIPayloadCommits(repoPath, repoLink string) ([]*api.Pa
|
|||
var headCommit *api.PayloadCommit
|
||||
|
||||
if pc.emailUsers == nil {
|
||||
pc.emailUsers = make(map[string]*models.User)
|
||||
pc.emailUsers = make(map[string]*user_model.User)
|
||||
}
|
||||
for i, commit := range pc.Commits {
|
||||
apiCommit, err := pc.toAPIPayloadCommit(repoPath, repoLink, commit)
|
||||
|
@ -146,10 +146,10 @@ func (pc *PushCommits) AvatarLink(email string) string {
|
|||
u, ok := pc.emailUsers[email]
|
||||
if !ok {
|
||||
var err error
|
||||
u, err = models.GetUserByEmail(email)
|
||||
u, err = user_model.GetUserByEmail(email)
|
||||
if err != nil {
|
||||
pc.avatars[email] = avatars.GenerateEmailAvatarFastLink(email, size)
|
||||
if !models.IsErrUserNotExist(err) {
|
||||
if !user_model.IsErrUserNotExist(err) {
|
||||
log.Error("GetUserByEmail: %v", err)
|
||||
return ""
|
||||
}
|
||||
|
@ -189,6 +189,6 @@ func GitToPushCommits(gitCommits []*git.Commit) *PushCommits {
|
|||
CompareURL: "",
|
||||
Len: len(commits),
|
||||
avatars: make(map[string]string),
|
||||
emailUsers: make(map[string]*models.User),
|
||||
emailUsers: make(map[string]*user_model.User),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue