diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-12-12 23:48:20 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-12 23:48:20 +0800 |
commit | 572324049008ac803d3d7c17a7b3a81ef00386fc (patch) | |
tree | a9c3709643a23165d27aa67e76f10f26a89936d5 /routers | |
parent | 0a7e8327a017c5dd43e552bbcd0d0f056bc1671b (diff) | |
download | gitea-572324049008ac803d3d7c17a7b3a81ef00386fc.tar.gz gitea-572324049008ac803d3d7c17a7b3a81ef00386fc.zip |
Some repository refactors (#17950)
* some repository refactors
* remove unnecessary code
* Fix test
* Remove unnecessary banner
Diffstat (limited to 'routers')
-rw-r--r-- | routers/api/v1/api.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/fork.go | 5 | ||||
-rw-r--r-- | routers/api/v1/repo/migrate.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 12 | ||||
-rw-r--r-- | routers/api/v1/repo/star.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/subscriber.go | 6 | ||||
-rw-r--r-- | routers/api/v1/repo/topic.go | 24 | ||||
-rw-r--r-- | routers/api/v1/repo/transfer.go | 2 | ||||
-rw-r--r-- | routers/api/v1/user/star.go | 7 | ||||
-rw-r--r-- | routers/api/v1/user/watch.go | 6 | ||||
-rw-r--r-- | routers/private/hook_post_receive.go | 2 | ||||
-rw-r--r-- | routers/web/org/setting.go | 3 | ||||
-rw-r--r-- | routers/web/repo/branch.go | 2 | ||||
-rw-r--r-- | routers/web/repo/compare.go | 6 | ||||
-rw-r--r-- | routers/web/repo/http.go | 2 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 2 | ||||
-rw-r--r-- | routers/web/repo/migrate.go | 9 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 10 | ||||
-rw-r--r-- | routers/web/repo/repo.go | 14 | ||||
-rw-r--r-- | routers/web/repo/setting.go | 16 | ||||
-rw-r--r-- | routers/web/repo/topic.go | 6 | ||||
-rw-r--r-- | routers/web/repo/view.go | 8 | ||||
-rw-r--r-- | routers/web/user/setting/profile.go | 4 |
24 files changed, 83 insertions, 79 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 1d7d4251db..af5ab96d05 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -161,10 +161,10 @@ func repoAssignment() func(ctx *context.APIContext) { repo, err := repo_model.GetRepositoryByName(owner.ID, repoName) if err != nil { if repo_model.IsErrRepoNotExist(err) { - redirectRepoID, err := models.LookupRepoRedirect(owner.ID, repoName) + redirectRepoID, err := repo_model.LookupRedirect(owner.ID, repoName) if err == nil { context.RedirectToRepo(ctx.Context, redirectRepoID) - } else if models.IsErrRepoRedirectNotExist(err) { + } else if repo_model.IsErrRedirectNotExist(err) { ctx.NotFound() } else { ctx.Error(http.StatusInternalServerError, "LookupRepoRedirect", err) diff --git a/routers/api/v1/repo/fork.go b/routers/api/v1/repo/fork.go index aa51019ebd..542af60741 100644 --- a/routers/api/v1/repo/fork.go +++ b/routers/api/v1/repo/fork.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/perm" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -50,7 +51,7 @@ func ListForks(ctx *context.APIContext) { // "200": // "$ref": "#/responses/RepositoryList" - forks, err := models.GetForks(ctx.Repo.Repository, utils.GetListOptions(ctx)) + forks, err := repo_model.GetForks(ctx.Repo.Repository, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetForks", err) return @@ -125,7 +126,7 @@ func CreateFork(ctx *context.APIContext) { forker = org.AsUser() } - fork, err := repo_service.ForkRepository(ctx.User, forker, models.ForkRepoOptions{ + fork, err := repo_service.ForkRepository(ctx.User, forker, repo_service.ForkRepoOptions{ BaseRepo: repo, Name: repo.Name, Description: repo.Description, diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index 108d78ef23..8a6f421c87 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -214,15 +214,15 @@ func Migrate(ctx *context.APIContext) { func handleMigrateError(ctx *context.APIContext, repoOwner *user_model.User, remoteAddr string, err error) { switch { - case models.IsErrRepoAlreadyExist(err): + case repo_model.IsErrRepoAlreadyExist(err): ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.") - case models.IsErrRepoFilesAlreadyExist(err): + case repo_model.IsErrRepoFilesAlreadyExist(err): ctx.Error(http.StatusConflict, "", "Files already exist for this repository. Adopt them or delete them.") case migrations.IsRateLimitError(err): ctx.Error(http.StatusUnprocessableEntity, "", "Remote visit addressed rate limitation.") case migrations.IsTwoFactorAuthError(err): ctx.Error(http.StatusUnprocessableEntity, "", "Remote visit required two factors authentication.") - case models.IsErrReachLimitOfRepo(err): + case repo_model.IsErrReachLimitOfRepo(err): ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("You have already reached your limit of %d repositories.", repoOwner.MaxCreationLimit())) case db.IsErrNameReserved(err): ctx.Error(http.StatusUnprocessableEntity, "", fmt.Sprintf("The username '%s' is reserved.", err.(db.ErrNameReserved).Name)) diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index e593819dac..0683fe4548 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -956,7 +956,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption) } // Check if current user has fork of repository or in the same repository. - headRepo := models.GetForkedRepo(headUser.ID, baseRepo.ID) + headRepo := repo_model.GetForkedRepo(headUser.ID, baseRepo.ID) if headRepo == nil && !isSameRepo { log.Trace("parseCompareInfo[%d]: does not have fork or in same repository", baseRepo.ID) ctx.NotFound("GetForkedRepo") diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 62f9c37244..340ba0f6d5 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -261,7 +261,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre IsTemplate: opt.Template, }) if err != nil { - if models.IsErrRepoAlreadyExist(err) { + if repo_model.IsErrRepoAlreadyExist(err) { ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.") } else if db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) { @@ -410,7 +410,7 @@ func Generate(ctx *context.APIContext) { repo, err := repo_service.GenerateRepository(ctx.User, ctxUser, ctx.Repo.Repository, opts) if err != nil { - if models.IsErrRepoAlreadyExist(err) { + if repo_model.IsErrRepoAlreadyExist(err) { ctx.Error(http.StatusConflict, "", "The repository with the same name already exists.") } else if db.IsErrNameReserved(err) || db.IsErrNamePatternNotAllowed(err) { @@ -650,7 +650,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err if repo.LowerName != strings.ToLower(newRepoName) { if err := repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName); err != nil { switch { - case models.IsErrRepoAlreadyExist(err): + case repo_model.IsErrRepoAlreadyExist(err): ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is already taken [name: %s]", newRepoName), err) case db.IsErrNameReserved(err): ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("repo name is reserved [name: %s]", newRepoName), err) @@ -911,7 +911,7 @@ func updateRepoUnits(ctx *context.APIContext, opts api.EditRepoOption) error { } } - if err := models.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil { + if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateRepositoryUnits", err) return err } @@ -931,14 +931,14 @@ func updateRepoArchivedState(ctx *context.APIContext, opts api.EditRepoOption) e return err } if *opts.Archived { - if err := models.SetArchiveRepoState(repo, *opts.Archived); err != nil { + if err := repo_model.SetArchiveRepoState(repo, *opts.Archived); err != nil { log.Error("Tried to archive a repo: %s", err) ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err) return err } log.Trace("Repository was archived: %s/%s", ctx.Repo.Owner.Name, repo.Name) } else { - if err := models.SetArchiveRepoState(repo, *opts.Archived); err != nil { + if err := repo_model.SetArchiveRepoState(repo, *opts.Archived); err != nil { log.Error("Tried to un-archive a repo: %s", err) ctx.Error(http.StatusInternalServerError, "ArchiveRepoState", err) return err diff --git a/routers/api/v1/repo/star.go b/routers/api/v1/repo/star.go index b8a54a6bda..a53ed7136f 100644 --- a/routers/api/v1/repo/star.go +++ b/routers/api/v1/repo/star.go @@ -7,7 +7,7 @@ package repo import ( "net/http" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -44,7 +44,7 @@ func ListStargazers(ctx *context.APIContext) { // "200": // "$ref": "#/responses/UserList" - stargazers, err := models.GetStargazers(ctx.Repo.Repository, utils.GetListOptions(ctx)) + stargazers, err := repo_model.GetStargazers(ctx.Repo.Repository, utils.GetListOptions(ctx)) if err != nil { ctx.Error(http.StatusInternalServerError, "GetStargazers", err) return diff --git a/routers/api/v1/repo/subscriber.go b/routers/api/v1/repo/subscriber.go index 64a0fc1d5d..31126d5695 100644 --- a/routers/api/v1/repo/subscriber.go +++ b/routers/api/v1/repo/subscriber.go @@ -7,7 +7,7 @@ package repo import ( "net/http" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" api "code.gitea.io/gitea/modules/structs" @@ -44,9 +44,9 @@ func ListSubscribers(ctx *context.APIContext) { // "200": // "$ref": "#/responses/UserList" - subscribers, err := models.GetRepoWatchers(ctx.Repo.Repository.ID, utils.GetListOptions(ctx)) + subscribers, err := repo_model.GetRepoWatchers(ctx.Repo.Repository.ID, utils.GetListOptions(ctx)) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetWatchers", err) + ctx.Error(http.StatusInternalServerError, "GetRepoWatchers", err) return } users := make([]*api.User, len(subscribers)) diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go index fc277cb3fe..1cc2c50dc2 100644 --- a/routers/api/v1/repo/topic.go +++ b/routers/api/v1/repo/topic.go @@ -8,7 +8,7 @@ import ( "net/http" "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" "code.gitea.io/gitea/modules/log" @@ -47,12 +47,12 @@ func ListTopics(ctx *context.APIContext) { // "200": // "$ref": "#/responses/TopicNames" - opts := &models.FindTopicOptions{ + opts := &repo_model.FindTopicOptions{ ListOptions: utils.GetListOptions(ctx), RepoID: ctx.Repo.Repository.ID, } - topics, total, err := models.FindTopics(opts) + topics, total, err := repo_model.FindTopics(opts) if err != nil { ctx.InternalServerError(err) return @@ -99,7 +99,7 @@ func UpdateTopics(ctx *context.APIContext) { form := web.GetForm(ctx).(*api.RepoTopicOptions) topicNames := form.Topics - validTopics, invalidTopics := models.SanitizeAndValidateTopics(topicNames) + validTopics, invalidTopics := repo_model.SanitizeAndValidateTopics(topicNames) if len(validTopics) > 25 { ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ @@ -117,7 +117,7 @@ func UpdateTopics(ctx *context.APIContext) { return } - err := models.SaveTopics(ctx.Repo.Repository.ID, validTopics...) + err := repo_model.SaveTopics(ctx.Repo.Repository.ID, validTopics...) if err != nil { log.Error("SaveTopics failed: %v", err) ctx.InternalServerError(err) @@ -158,7 +158,7 @@ func AddTopic(ctx *context.APIContext) { topicName := strings.TrimSpace(strings.ToLower(ctx.Params(":topic"))) - if !models.ValidateTopic(topicName) { + if !repo_model.ValidateTopic(topicName) { ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ "invalidTopics": topicName, "message": "Topic name is invalid", @@ -167,7 +167,7 @@ func AddTopic(ctx *context.APIContext) { } // Prevent adding more topics than allowed to repo - count, err := models.CountTopics(&models.FindTopicOptions{ + count, err := repo_model.CountTopics(&repo_model.FindTopicOptions{ RepoID: ctx.Repo.Repository.ID, }) if err != nil { @@ -182,7 +182,7 @@ func AddTopic(ctx *context.APIContext) { return } - _, err = models.AddTopic(ctx.Repo.Repository.ID, topicName) + _, err = repo_model.AddTopic(ctx.Repo.Repository.ID, topicName) if err != nil { log.Error("AddTopic failed: %v", err) ctx.InternalServerError(err) @@ -223,7 +223,7 @@ func DeleteTopic(ctx *context.APIContext) { topicName := strings.TrimSpace(strings.ToLower(ctx.Params(":topic"))) - if !models.ValidateTopic(topicName) { + if !repo_model.ValidateTopic(topicName) { ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ "invalidTopics": topicName, "message": "Topic name is invalid", @@ -231,7 +231,7 @@ func DeleteTopic(ctx *context.APIContext) { return } - topic, err := models.DeleteTopic(ctx.Repo.Repository.ID, topicName) + topic, err := repo_model.DeleteTopic(ctx.Repo.Repository.ID, topicName) if err != nil { log.Error("DeleteTopic failed: %v", err) ctx.InternalServerError(err) @@ -272,12 +272,12 @@ func TopicSearch(ctx *context.APIContext) { // "403": // "$ref": "#/responses/forbidden" - opts := &models.FindTopicOptions{ + opts := &repo_model.FindTopicOptions{ Keyword: ctx.FormString("q"), ListOptions: utils.GetListOptions(ctx), } - topics, total, err := models.FindTopics(opts) + topics, total, err := repo_model.FindTopics(opts) if err != nil { ctx.InternalServerError(err) return diff --git a/routers/api/v1/repo/transfer.go b/routers/api/v1/repo/transfer.go index e2a83c70ec..abaed4d587 100644 --- a/routers/api/v1/repo/transfer.go +++ b/routers/api/v1/repo/transfer.go @@ -104,7 +104,7 @@ func Transfer(ctx *context.APIContext) { return } - if models.IsErrRepoAlreadyExist(err) { + if repo_model.IsErrRepoAlreadyExist(err) { ctx.Error(http.StatusUnprocessableEntity, "CreatePendingRepositoryTransfer", err) return } diff --git a/routers/api/v1/user/star.go b/routers/api/v1/user/star.go index 946ae738e9..14bc23b1c3 100644 --- a/routers/api/v1/user/star.go +++ b/routers/api/v1/user/star.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/convert" @@ -121,7 +122,7 @@ func IsStarring(ctx *context.APIContext) { // "404": // "$ref": "#/responses/notFound" - if models.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) { + if repo_model.IsStaring(ctx.User.ID, ctx.Repo.Repository.ID) { ctx.Status(http.StatusNoContent) } else { ctx.NotFound() @@ -148,7 +149,7 @@ func Star(ctx *context.APIContext) { // "204": // "$ref": "#/responses/empty" - err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) + err := repo_model.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) if err != nil { ctx.Error(http.StatusInternalServerError, "StarRepo", err) return @@ -176,7 +177,7 @@ func Unstar(ctx *context.APIContext) { // "204": // "$ref": "#/responses/empty" - err := models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) + err := repo_model.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) if err != nil { ctx.Error(http.StatusInternalServerError, "StarRepo", err) return diff --git a/routers/api/v1/user/watch.go b/routers/api/v1/user/watch.go index 5c7a4d8d89..6c3e1c86fa 100644 --- a/routers/api/v1/user/watch.go +++ b/routers/api/v1/user/watch.go @@ -123,7 +123,7 @@ func IsWatching(ctx *context.APIContext) { // "404": // description: User is not watching this repo or repo do not exist - if models.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) { + if repo_model.IsWatching(ctx.User.ID, ctx.Repo.Repository.ID) { ctx.JSON(http.StatusOK, api.WatchInfo{ Subscribed: true, Ignored: false, @@ -157,7 +157,7 @@ func Watch(ctx *context.APIContext) { // "200": // "$ref": "#/responses/WatchInfo" - err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) + err := repo_model.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) if err != nil { ctx.Error(http.StatusInternalServerError, "WatchRepo", err) return @@ -193,7 +193,7 @@ func Unwatch(ctx *context.APIContext) { // "204": // "$ref": "#/responses/empty" - err := models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) + err := repo_model.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) if err != nil { ctx.Error(http.StatusInternalServerError, "UnwatchRepo", err) return diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go index a71f465911..7124ae9e81 100644 --- a/routers/private/hook_post_receive.go +++ b/routers/private/hook_post_receive.go @@ -105,7 +105,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) { repo.IsPrivate = opts.GitPushOptions.Bool(private.GitPushOptionRepoPrivate, repo.IsPrivate) repo.IsTemplate = opts.GitPushOptions.Bool(private.GitPushOptionRepoTemplate, repo.IsTemplate) - if err := models.UpdateRepositoryCols(repo, "is_private", "is_template"); err != nil { + if err := repo_model.UpdateRepositoryCols(repo, "is_private", "is_template"); err != nil { log.Error("Failed to Update: %s/%s Error: %v", ownerName, repoName, err) ctx.JSON(http.StatusInternalServerError, private.HookPostReceiveResult{ Err: fmt.Sprintf("Failed to Update: %s/%s Error: %v", ownerName, repoName, err), diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go index 6c7f9ed62b..081e103f79 100644 --- a/routers/web/org/setting.go +++ b/routers/web/org/setting.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/models/webhook" "code.gitea.io/gitea/modules/base" @@ -125,7 +126,7 @@ func SettingsPost(ctx *context.Context) { } } } else if nameChanged { - if err := models.UpdateRepositoryOwnerNames(org.ID, org.Name); err != nil { + if err := repo_model.UpdateRepositoryOwnerNames(org.ID, org.Name); err != nil { ctx.ServerError("UpdateRepository", err) return } diff --git a/routers/web/repo/branch.go b/routers/web/repo/branch.go index f6a475c3c9..d8f7b7ef2f 100644 --- a/routers/web/repo/branch.go +++ b/routers/web/repo/branch.go @@ -56,7 +56,7 @@ func Branches(ctx *context.Context) { ctx.Data["IsWriter"] = ctx.Repo.CanWrite(unit.TypeCode) ctx.Data["IsMirror"] = ctx.Repo.Repository.IsMirror ctx.Data["CanPull"] = ctx.Repo.CanWrite(unit.TypeCode) || - (ctx.IsSigned && models.HasForkedRepo(ctx.User.ID, ctx.Repo.Repository.ID)) + (ctx.IsSigned && repo_model.HasForkedRepo(ctx.User.ID, ctx.Repo.Repository.ID)) ctx.Data["PageIsViewCode"] = true ctx.Data["PageIsBranches"] = true diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index c92624df8c..8d08fec8fd 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -340,7 +340,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { // "OwnForkRepo" var ownForkRepo *repo_model.Repository if ctx.User != nil && baseRepo.OwnerID != ctx.User.ID { - repo := models.GetForkedRepo(ctx.User.ID, baseRepo.ID) + repo := repo_model.GetForkedRepo(ctx.User.ID, baseRepo.ID) if repo != nil { ownForkRepo = repo ctx.Data["OwnForkRepo"] = ownForkRepo @@ -364,13 +364,13 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { // 5. If the headOwner has a fork of the baseRepo - use that if !has { - ci.HeadRepo = models.GetForkedRepo(ci.HeadUser.ID, baseRepo.ID) + ci.HeadRepo = repo_model.GetForkedRepo(ci.HeadUser.ID, baseRepo.ID) has = ci.HeadRepo != nil } // 6. If the baseRepo is a fork and the headUser has a fork of that use that if !has && baseRepo.IsFork { - ci.HeadRepo = models.GetForkedRepo(ci.HeadUser.ID, baseRepo.ForkID) + ci.HeadRepo = repo_model.GetForkedRepo(ci.HeadUser.ID, baseRepo.ForkID) has = ci.HeadRepo != nil } diff --git a/routers/web/repo/http.go b/routers/web/repo/http.go index 3e12cd3267..107f1d960a 100644 --- a/routers/web/repo/http.go +++ b/routers/web/repo/http.go @@ -134,7 +134,7 @@ func httpBase(ctx *context.Context) (h *serviceHandler) { repo, err := repo_model.GetRepositoryByName(owner.ID, reponame) if err != nil { if repo_model.IsErrRepoNotExist(err) { - if redirectRepoID, err := models.LookupRepoRedirect(owner.ID, reponame); err == nil { + if redirectRepoID, err := repo_model.LookupRedirect(owner.ID, reponame); err == nil { context.RedirectToRepo(ctx, redirectRepoID) return } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index f03a8dfbc2..464646a868 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -108,7 +108,7 @@ func MustAllowPulls(ctx *context.Context) { } // User can send pull request if owns a forked repository. - if ctx.IsSigned && models.HasForkedRepo(ctx.User.ID, ctx.Repo.Repository.ID) { + if ctx.IsSigned && repo_model.HasForkedRepo(ctx.User.ID, ctx.Repo.Repository.ID) { ctx.Repo.PullRequest.Allowed = true ctx.Repo.PullRequest.HeadInfoSubURL = url.PathEscape(ctx.User.Name) + ":" + util.PathEscapeSegments(ctx.Repo.BranchName) } diff --git a/routers/web/repo/migrate.go b/routers/web/repo/migrate.go index 5eba4690d0..4284734102 100644 --- a/routers/web/repo/migrate.go +++ b/routers/web/repo/migrate.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" + repo_model "code.gitea.io/gitea/models/repo" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" @@ -79,12 +80,12 @@ func handleMigrateError(ctx *context.Context, owner *user_model.User, err error, ctx.RenderWithErr(ctx.Tr("form.visit_rate_limit"), tpl, form) case migrations.IsTwoFactorAuthError(err): ctx.RenderWithErr(ctx.Tr("form.2fa_auth_required"), tpl, form) - case models.IsErrReachLimitOfRepo(err): + case repo_model.IsErrReachLimitOfRepo(err): ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form) - case models.IsErrRepoAlreadyExist(err): + case repo_model.IsErrRepoAlreadyExist(err): ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form) - case models.IsErrRepoFilesAlreadyExist(err): + case repo_model.IsErrRepoFilesAlreadyExist(err): ctx.Data["Err_RepoName"] = true switch { case ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories): @@ -230,7 +231,7 @@ func MigratePost(ctx *context.Context) { opts.Releases = false } - err = models.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName, false) + err = repo_model.CheckCreateRepository(ctx.User, ctxUser, opts.RepoName, false) if err != nil { handleMigrateError(ctx, ctxUser, err, "MigratePost", tpl, form) return diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 3882fdb5b1..2fcee33a23 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -110,7 +110,7 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository { ctx.Data["repo_name"] = forkRepo.Name ctx.Data["description"] = forkRepo.Description ctx.Data["IsPrivate"] = forkRepo.IsPrivate || forkRepo.Owner.Visibility == structs.VisibleTypePrivate - canForkToUser := forkRepo.OwnerID != ctx.User.ID && !models.HasForkedRepo(ctx.User.ID, forkRepo.ID) + canForkToUser := forkRepo.OwnerID != ctx.User.ID && !repo_model.HasForkedRepo(ctx.User.ID, forkRepo.ID) ctx.Data["ForkRepo"] = forkRepo @@ -121,7 +121,7 @@ func getForkRepository(ctx *context.Context) *repo_model.Repository { } var orgs []*models.Organization for _, org := range ownedOrgs { - if forkRepo.OwnerID != org.ID && !models.HasForkedRepo(org.ID, forkRepo.ID) { + if forkRepo.OwnerID != org.ID && !repo_model.HasForkedRepo(org.ID, forkRepo.ID) { orgs = append(orgs, org) } } @@ -202,7 +202,7 @@ func ForkPost(ctx *context.Context) { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form) return } - repo := models.GetForkedRepo(ctxUser.ID, traverseParentRepo.ID) + repo := repo_model.GetForkedRepo(ctxUser.ID, traverseParentRepo.ID) if repo != nil { ctx.Redirect(ctxUser.HomeLink() + "/" + url.PathEscape(repo.Name)) return @@ -229,7 +229,7 @@ func ForkPost(ctx *context.Context) { } } - repo, err := repo_service.ForkRepository(ctx.User, ctxUser, models.ForkRepoOptions{ + repo, err := repo_service.ForkRepository(ctx.User, ctxUser, repo_service.ForkRepoOptions{ BaseRepo: forkRepo, Name: form.RepoName, Description: form.Description, @@ -237,7 +237,7 @@ func ForkPost(ctx *context.Context) { if err != nil { ctx.Data["Err_RepoName"] = true switch { - case models.IsErrRepoAlreadyExist(err): + case repo_model.IsErrRepoAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form) case db.IsErrNameReserved(err): ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplFork, &form) diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index b4bab5960b..a1e652f94c 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -161,12 +161,12 @@ func Create(ctx *context.Context) { func handleCreateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form interface{}) { switch { - case models.IsErrReachLimitOfRepo(err): + case repo_model.IsErrReachLimitOfRepo(err): ctx.RenderWithErr(ctx.Tr("repo.form.reach_limit_of_creation", owner.MaxCreationLimit()), tpl, form) - case models.IsErrRepoAlreadyExist(err): + case repo_model.IsErrRepoAlreadyExist(err): ctx.Data["Err_RepoName"] = true ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form) - case models.IsErrRepoFilesAlreadyExist(err): + case repo_model.IsErrRepoFilesAlreadyExist(err): ctx.Data["Err_RepoName"] = true switch { case ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories): @@ -278,13 +278,13 @@ func Action(ctx *context.Context) { var err error switch ctx.Params(":action") { case "watch": - err = models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) + err = repo_model.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) case "unwatch": - err = models.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) + err = repo_model.WatchRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) case "star": - err = models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) + err = repo_model.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, true) case "unstar": - err = models.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) + err = repo_model.StarRepo(ctx.User.ID, ctx.Repo.Repository.ID, false) case "accept_transfer": err = acceptOrRejectRepoTransfer(ctx, true) case "reject_transfer": diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index bb118a9035..81009cb393 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -103,11 +103,11 @@ func SettingsPost(ctx *context.Context) { if err := repo_service.ChangeRepositoryName(ctx.User, repo, newRepoName); err != nil { ctx.Data["Err_RepoName"] = true switch { - case models.IsErrRepoAlreadyExist(err): + case repo_model.IsErrRepoAlreadyExist(err): ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tplSettingsOptions, &form) case db.IsErrNameReserved(err): ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplSettingsOptions, &form) - case models.IsErrRepoFilesAlreadyExist(err): + case repo_model.IsErrRepoFilesAlreadyExist(err): ctx.Data["Err_RepoName"] = true switch { case ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories): @@ -461,7 +461,7 @@ func SettingsPost(ctx *context.Context) { deleteUnitTypes = append(deleteUnitTypes, unit_model.TypePullRequests) } - if err := models.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil { + if err := repo_model.UpdateRepositoryUnits(repo, units, deleteUnitTypes); err != nil { ctx.ServerError("UpdateRepositoryUnits", err) return } @@ -612,7 +612,7 @@ func SettingsPost(ctx *context.Context) { } if err := repo_service.StartRepositoryTransfer(ctx.User, newOwner, repo, nil); err != nil { - if models.IsErrRepoAlreadyExist(err) { + if repo_model.IsErrRepoAlreadyExist(err) { ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplSettingsOptions, nil) } else if models.IsErrRepoTransferInProgress(err) { ctx.RenderWithErr(ctx.Tr("repo.settings.transfer_in_progress"), tplSettingsOptions, nil) @@ -714,7 +714,7 @@ func SettingsPost(ctx *context.Context) { return } - if err := models.SetArchiveRepoState(repo, true); err != nil { + if err := repo_model.SetArchiveRepoState(repo, true); err != nil { log.Error("Tried to archive a repo: %s", err) ctx.Flash.Error(ctx.Tr("repo.settings.archive.error")) ctx.Redirect(ctx.Repo.RepoLink + "/settings") @@ -732,7 +732,7 @@ func SettingsPost(ctx *context.Context) { return } - if err := models.SetArchiveRepoState(repo, false); err != nil { + if err := repo_model.SetArchiveRepoState(repo, false); err != nil { log.Error("Tried to unarchive a repo: %s", err) ctx.Flash.Error(ctx.Tr("repo.settings.unarchive.error")) ctx.Redirect(ctx.Repo.RepoLink + "/settings") @@ -1145,7 +1145,7 @@ func UpdateAvatarSetting(ctx *context.Context, form forms.AvatarForm) error { if !(st.IsImage() && !st.IsSvgImage()) { return errors.New(ctx.Tr("settings.uploaded_avatar_not_a_image")) } - if err = models.UploadRepoAvatar(ctxRepo, data); err != nil { + if err = repo_service.UploadAvatar(ctxRepo, data); err != nil { return fmt.Errorf("UploadAvatar: %v", err) } return nil @@ -1165,7 +1165,7 @@ func SettingsAvatar(ctx *context.Context) { // SettingsDeleteAvatar delete repository avatar func SettingsDeleteAvatar(ctx *context.Context) { - if err := models.DeleteRepoAvatar(ctx.Repo.Repository); err != nil { + if err := repo_service.DeleteAvatar(ctx.Repo.Repository); err != nil { ctx.Flash.Error(fmt.Sprintf("DeleteAvatar: %v", err)) } ctx.Redirect(ctx.Repo.RepoLink + "/settings") diff --git a/routers/web/repo/topic.go b/routers/web/repo/topic.go index 41e3f995b6..810b241e28 100644 --- a/routers/web/repo/topic.go +++ b/routers/web/repo/topic.go @@ -8,7 +8,7 @@ import ( "net/http" "strings" - "code.gitea.io/gitea/models" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" ) @@ -28,7 +28,7 @@ func TopicsPost(ctx *context.Context) { topics = strings.Split(topicsStr, ",") } - validTopics, invalidTopics := models.SanitizeAndValidateTopics(topics) + validTopics, invalidTopics := repo_model.SanitizeAndValidateTopics(topics) if len(validTopics) > 25 { ctx.JSON(http.StatusUnprocessableEntity, map[string]interface{}{ @@ -46,7 +46,7 @@ func TopicsPost(ctx *context.Context) { return } - err := models.SaveTopics(ctx.Repo.Repository.ID, validTopics...) + err := repo_model.SaveTopics(ctx.Repo.Repository.ID, validTopics...) if err != nil { log.Error("SaveTopics failed: %v", err) ctx.JSON(http.StatusInternalServerError, map[string]interface{}{ diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 9e0f670cf9..5e9003b16b 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -822,7 +822,7 @@ func renderLanguageStats(ctx *context.Context) { } func renderRepoTopics(ctx *context.Context) { - topics, _, err := models.FindTopics(&models.FindTopicOptions{ + topics, _, err := repo_model.FindTopics(&repo_model.FindTopicOptions{ RepoID: ctx.Repo.Repository.ID, }) if err != nil { @@ -931,7 +931,7 @@ func Watchers(ctx *context.Context) { ctx.Data["PageIsWatchers"] = true RenderUserCards(ctx, ctx.Repo.Repository.NumWatches, func(opts db.ListOptions) ([]*user_model.User, error) { - return models.GetRepoWatchers(ctx.Repo.Repository.ID, opts) + return repo_model.GetRepoWatchers(ctx.Repo.Repository.ID, opts) }, tplWatchers) } @@ -941,7 +941,7 @@ func Stars(ctx *context.Context) { ctx.Data["CardsTitle"] = ctx.Tr("repo.stargazers") ctx.Data["PageIsStargazers"] = true RenderUserCards(ctx, ctx.Repo.Repository.NumStars, func(opts db.ListOptions) ([]*user_model.User, error) { - return models.GetStargazers(ctx.Repo.Repository, opts) + return repo_model.GetStargazers(ctx.Repo.Repository, opts) }, tplWatchers) } @@ -957,7 +957,7 @@ func Forks(ctx *context.Context) { pager := context.NewPagination(ctx.Repo.Repository.NumForks, models.ItemsPerPage, page, 5) ctx.Data["Page"] = pager - forks, err := models.GetForks(ctx.Repo.Repository, db.ListOptions{ + forks, err := repo_model.GetForks(ctx.Repo.Repository, db.ListOptions{ Page: pager.Paginater.Current(), PageSize: models.ItemsPerPage, }) diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go index 089177874a..ab156b43fc 100644 --- a/routers/web/user/setting/profile.go +++ b/routers/web/user/setting/profile.go @@ -77,7 +77,7 @@ func HandleUsernameChange(ctx *context.Context, user *user_model.User, newName s return err } } else { - if err := models.UpdateRepositoryOwnerNames(user.ID, newName); err != nil { + if err := repo_model.UpdateRepositoryOwnerNames(user.ID, newName); err != nil { ctx.ServerError("UpdateRepository", err) return err } @@ -290,7 +290,7 @@ func Repos(ctx *context.Context) { return filepath.SkipDir } name = name[:len(name)-4] - if models.IsUsableRepoName(name) != nil || strings.ToLower(name) != name { + if repo_model.IsUsableRepoName(name) != nil || strings.ToLower(name) != name { return filepath.SkipDir } if count >= start && count < end { |