From a666829a37be6f9fd98f9e7dd1767c420f7f3b32 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 24 Nov 2021 17:49:20 +0800 Subject: 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 --- services/task/migrate.go | 12 +++++++----- services/task/task.go | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) (limited to 'services/task') diff --git a/services/task/migrate.go b/services/task/migrate.go index 100aac1967..46ea80b002 100644 --- a/services/task/migrate.go +++ b/services/task/migrate.go @@ -11,6 +11,8 @@ import ( "strings" "code.gitea.io/gitea/models" + "code.gitea.io/gitea/models/db" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" @@ -23,16 +25,16 @@ import ( "code.gitea.io/gitea/services/migrations" ) -func handleCreateError(owner *models.User, err error) error { +func handleCreateError(owner *user_model.User, err error) error { switch { case models.IsErrReachLimitOfRepo(err): return fmt.Errorf("You have already reached your limit of %d repositories", owner.MaxCreationLimit()) case models.IsErrRepoAlreadyExist(err): return errors.New("The repository name is already used") - case models.IsErrNameReserved(err): - return fmt.Errorf("The repository name '%s' is reserved", err.(models.ErrNameReserved).Name) - case models.IsErrNamePatternNotAllowed(err): - return fmt.Errorf("The pattern '%s' is not allowed in a repository name", err.(models.ErrNamePatternNotAllowed).Pattern) + case db.IsErrNameReserved(err): + return fmt.Errorf("The repository name '%s' is reserved", err.(db.ErrNameReserved).Name) + case db.IsErrNamePatternNotAllowed(err): + return fmt.Errorf("The pattern '%s' is not allowed in a repository name", err.(db.ErrNamePatternNotAllowed).Pattern) default: return err } diff --git a/services/task/task.go b/services/task/task.go index f538b36efc..350b8206b2 100644 --- a/services/task/task.go +++ b/services/task/task.go @@ -8,6 +8,7 @@ import ( "fmt" "code.gitea.io/gitea/models" + user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/graceful" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" @@ -57,7 +58,7 @@ func handle(data ...queue.Data) { } // MigrateRepository add migration repository to task -func MigrateRepository(doer, u *models.User, opts base.MigrateOptions) error { +func MigrateRepository(doer, u *user_model.User, opts base.MigrateOptions) error { task, err := CreateMigrateTask(doer, u, opts) if err != nil { return err @@ -67,7 +68,7 @@ func MigrateRepository(doer, u *models.User, opts base.MigrateOptions) error { } // CreateMigrateTask creates a migrate task -func CreateMigrateTask(doer, u *models.User, opts base.MigrateOptions) (*models.Task, error) { +func CreateMigrateTask(doer, u *user_model.User, opts base.MigrateOptions) (*models.Task, error) { // encrypt credentials for persistence var err error opts.CloneAddrEncrypted, err = secret.EncryptSecret(setting.SecretKey, opts.CloneAddr) -- cgit v1.2.3