summaryrefslogtreecommitdiffstats
path: root/modules/repository
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-11-24 17:49:20 +0800
committerGitHub <noreply@github.com>2021-11-24 17:49:20 +0800
commita666829a37be6f9fd98f9e7dd1767c420f7f3b32 (patch)
tree9ab1434b759a8a2cb275a83149903a823851e309 /modules/repository
parent4e7ca946da2a2642a62f114825129bf5d7ed9196 (diff)
downloadgitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.tar.gz
gitea-a666829a37be6f9fd98f9e7dd1767c420f7f3b32.zip
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
Diffstat (limited to 'modules/repository')
-rw-r--r--modules/repository/commits.go18
-rw-r--r--modules/repository/create.go3
-rw-r--r--modules/repository/create_test.go5
-rw-r--r--modules/repository/generate.go3
-rw-r--r--modules/repository/init.go5
-rw-r--r--modules/repository/repo.go9
6 files changed, 24 insertions, 19 deletions
diff --git a/modules/repository/commits.go b/modules/repository/commits.go
index a545ce952b..8e727c95d0 100644
--- a/modules/repository/commits.go
+++ b/modules/repository/commits.go
@@ -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),
}
}
diff --git a/modules/repository/create.go b/modules/repository/create.go
index 64d92eeb2d..850f7488bd 100644
--- a/modules/repository/create.go
+++ b/modules/repository/create.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -18,7 +19,7 @@ import (
)
// CreateRepository creates a repository for the user/organization.
-func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*models.Repository, error) {
+func CreateRepository(doer, u *user_model.User, opts models.CreateRepoOptions) (*models.Repository, error) {
if !doer.IsAdmin && !u.CanCreateRepo() {
return nil, models.ErrReachLimitOfRepo{
Limit: u.MaxRepoCreation,
diff --git a/modules/repository/create_test.go b/modules/repository/create_test.go
index 12fc7afeeb..d7d3281872 100644
--- a/modules/repository/create_test.go
+++ b/modules/repository/create_test.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/structs"
"github.com/stretchr/testify/assert"
@@ -32,14 +33,14 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
}
// Get an admin user.
- user, err := models.GetUserByID(1)
+ user, err := user_model.GetUserByID(1)
assert.NoError(t, err, "GetUserByID")
// Create org.
org := &models.Organization{
Name: "All_repo",
IsActive: true,
- Type: models.UserTypeOrganization,
+ Type: user_model.UserTypeOrganization,
Visibility: structs.VisibleTypePublic,
}
assert.NoError(t, models.CreateOrganization(org, user), "CreateOrganization")
diff --git a/modules/repository/generate.go b/modules/repository/generate.go
index f6b76b14af..61a8b0d111 100644
--- a/modules/repository/generate.go
+++ b/modules/repository/generate.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
@@ -239,7 +240,7 @@ func GenerateGitContent(ctx context.Context, templateRepo, generateRepo *models.
}
// GenerateRepository generates a repository from a template
-func GenerateRepository(ctx context.Context, doer, owner *models.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
+func GenerateRepository(ctx context.Context, doer, owner *user_model.User, templateRepo *models.Repository, opts models.GenerateRepoOptions) (_ *models.Repository, err error) {
generateRepo := &models.Repository{
OwnerID: owner.ID,
Owner: owner,
diff --git a/modules/repository/init.go b/modules/repository/init.go
index 076dbf748e..d7f31fabde 100644
--- a/modules/repository/init.go
+++ b/modules/repository/init.go
@@ -14,6 +14,7 @@ import (
"time"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
@@ -100,7 +101,7 @@ func prepareRepoCommit(ctx context.Context, repo *models.Repository, tmpDir, rep
}
// initRepoCommit temporarily changes with work directory.
-func initRepoCommit(tmpPath string, repo *models.Repository, u *models.User, defaultBranch string) (err error) {
+func initRepoCommit(tmpPath string, repo *models.Repository, u *user_model.User, defaultBranch string) (err error) {
commitTimeStr := time.Now().Format(time.RFC3339)
sig := u.NewGitSig()
@@ -197,7 +198,7 @@ func checkInitRepository(owner, name string) (err error) {
}
// InitRepository initializes README and .gitignore if needed.
-func initRepository(ctx context.Context, repoPath string, u *models.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
+func initRepository(ctx context.Context, repoPath string, u *user_model.User, repo *models.Repository, opts models.CreateRepoOptions) (err error) {
if err = checkInitRepository(repo.OwnerName, repo.Name); err != nil {
return err
}
diff --git a/modules/repository/repo.go b/modules/repository/repo.go
index dd54a99cc9..c7145658f8 100644
--- a/modules/repository/repo.go
+++ b/modules/repository/repo.go
@@ -15,6 +15,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/lfs"
"code.gitea.io/gitea/modules/log"
@@ -46,7 +47,7 @@ func WikiRemoteURL(remote string) string {
}
// MigrateRepositoryGitData starts migrating git related data after created migrating repository
-func MigrateRepositoryGitData(ctx context.Context, u *models.User,
+func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
repo *models.Repository, opts migration.MigrateOptions,
httpTransport *http.Transport,
) (*models.Repository, error) {
@@ -307,12 +308,12 @@ func PushUpdateAddTag(repo *models.Repository, gitRepo *git.Repository, tagName
sig = commit.Committer
}
- var author *models.User
+ var author *user_model.User
var createdAt = time.Unix(1, 0)
if sig != nil {
- author, err = models.GetUserByEmail(sig.Email)
- if err != nil && !models.IsErrUserNotExist(err) {
+ author, err = user_model.GetUserByEmail(sig.Email)
+ if err != nil && !user_model.IsErrUserNotExist(err) {
return fmt.Errorf("GetUserByEmail: %v", err)
}
createdAt = sig.When