diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-06-06 16:01:49 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-06 16:01:49 +0800 |
commit | 26095115f4ae90e3fdc6ab695978efd16e317f75 (patch) | |
tree | 92ec1c7ff54e0a65f4f0662baa8c0244dd9f324b /routers/web/repo | |
parent | ebeb6e7c71a0c763b52153f4eb427e7c5b89a95e (diff) | |
download | gitea-26095115f4ae90e3fdc6ab695978efd16e317f75.tar.gz gitea-26095115f4ae90e3fdc6ab695978efd16e317f75.zip |
Move some repository related code into sub package (#19711)
* Move some repository related code into sub package
* Move more repository functions out of models
* Fix lint
* Some performance optimization for webhooks and others
* some refactors
* Fix lint
* Fix
* Update modules/repository/delete.go
Co-authored-by: delvh <dev.lh@web.de>
* Fix test
* Merge
* Fix test
* Fix test
* Fix test
* Fix test
Co-authored-by: delvh <dev.lh@web.de>
Diffstat (limited to 'routers/web/repo')
-rw-r--r-- | routers/web/repo/attachment.go | 4 | ||||
-rw-r--r-- | routers/web/repo/compare.go | 4 | ||||
-rw-r--r-- | routers/web/repo/issue.go | 15 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 2 | ||||
-rw-r--r-- | routers/web/repo/repo.go | 10 | ||||
-rw-r--r-- | routers/web/repo/setting.go | 8 | ||||
-rw-r--r-- | routers/web/repo/view.go | 3 |
7 files changed, 24 insertions, 22 deletions
diff --git a/routers/web/repo/attachment.go b/routers/web/repo/attachment.go index 701236f838..190dc6c2c7 100644 --- a/routers/web/repo/attachment.go +++ b/routers/web/repo/attachment.go @@ -8,7 +8,6 @@ import ( "fmt" "net/http" - "code.gitea.io/gitea/models" access_model "code.gitea.io/gitea/models/perm/access" repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/modules/context" @@ -19,6 +18,7 @@ import ( "code.gitea.io/gitea/modules/upload" "code.gitea.io/gitea/routers/common" "code.gitea.io/gitea/services/attachment" + repo_service "code.gitea.io/gitea/services/repository" ) // UploadIssueAttachment response for Issue/PR attachments @@ -95,7 +95,7 @@ func GetAttachment(ctx *context.Context) { return } - repository, unitType, err := models.LinkedRepository(attach) + repository, unitType, err := repo_service.LinkedRepository(attach) if err != nil { ctx.ServerError("LinkedRepository", err) return diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 9f94489235..d3653f04e9 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -457,7 +457,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { if rootRepo != nil && rootRepo.ID != ci.HeadRepo.ID && rootRepo.ID != baseRepo.ID { - canRead := models.CheckRepoUnitUser(rootRepo, ctx.Doer, unit.TypeCode) + canRead := models.CheckRepoUnitUser(ctx, rootRepo, ctx.Doer, unit.TypeCode) if canRead { ctx.Data["RootRepo"] = rootRepo if !fileOnly { @@ -482,7 +482,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo { ownForkRepo.ID != ci.HeadRepo.ID && ownForkRepo.ID != baseRepo.ID && (rootRepo == nil || ownForkRepo.ID != rootRepo.ID) { - canRead := models.CheckRepoUnitUser(ownForkRepo, ctx.Doer, unit.TypeCode) + canRead := models.CheckRepoUnitUser(ctx, ownForkRepo, ctx.Doer, unit.TypeCode) if canRead { ctx.Data["OwnForkRepo"] = ownForkRepo if !fileOnly { diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index d418907a1f..4a732ba454 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -49,6 +49,7 @@ import ( "code.gitea.io/gitea/services/forms" issue_service "code.gitea.io/gitea/services/issue" pull_service "code.gitea.io/gitea/services/pull" + repo_service "code.gitea.io/gitea/services/repository" ) const ( @@ -283,7 +284,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption uti ctx.Data["CommitStatuses"] = commitStatuses // Get assignees. - ctx.Data["Assignees"], err = models.GetRepoAssignees(repo) + ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, repo) if err != nil { ctx.ServerError("GetAssignees", err) return @@ -441,7 +442,7 @@ func RetrieveRepoMilestonesAndAssignees(ctx *context.Context, repo *repo_model.R return } - ctx.Data["Assignees"], err = models.GetRepoAssignees(repo) + ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, repo) if err != nil { ctx.ServerError("GetAssignees", err) return @@ -522,13 +523,13 @@ func RetrieveRepoReviewers(ctx *context.Context, repo *repo_model.Repository, is posterID = 0 } - reviewers, err = models.GetReviewers(repo, ctx.Doer.ID, posterID) + reviewers, err = repo_model.GetReviewers(ctx, repo, ctx.Doer.ID, posterID) if err != nil { ctx.ServerError("GetReviewers", err) return } - teamReviewers, err = models.GetReviewerTeams(repo) + teamReviewers, err = repo_service.GetReviewerTeams(repo) if err != nil { ctx.ServerError("GetReviewerTeams", err) return @@ -2160,7 +2161,7 @@ func SearchIssues(ctx *context.Context) { } // find repos user can access (for issue search) - opts := &models.SearchRepoOptions{ + opts := &repo_model.SearchRepoOptions{ Private: false, AllPublic: true, TopicOnly: false, @@ -2206,8 +2207,8 @@ func SearchIssues(ctx *context.Context) { opts.TeamID = team.ID } - repoCond := models.SearchRepositoryCondition(opts) - repoIDs, _, err := models.SearchRepositoryIDs(opts) + repoCond := repo_model.SearchRepositoryCondition(opts) + repoIDs, _, err := repo_model.SearchRepositoryIDs(opts) if err != nil { ctx.Error(http.StatusInternalServerError, "SearchRepositoryByName", err.Error()) return diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 3f24be33d6..8df4ccc607 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -758,7 +758,7 @@ func ViewPullFiles(ctx *context.Context) { setCompareContext(ctx, baseCommit, commit, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name) ctx.Data["RequireTribute"] = true - if ctx.Data["Assignees"], err = models.GetRepoAssignees(ctx.Repo.Repository); err != nil { + if ctx.Data["Assignees"], err = repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository); err != nil { ctx.ServerError("GetAssignees", err) return } diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 30cb888dce..c2c79e4a0d 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -152,7 +152,7 @@ func Create(ctx *context.Context) { templateID := ctx.FormInt64("template_id") if templateID > 0 { templateRepo, err := repo_model.GetRepositoryByID(templateID) - if err == nil && models.CheckRepoUnitUser(templateRepo, ctxUser, unit.TypeCode) { + if err == nil && models.CheckRepoUnitUser(ctx, templateRepo, ctxUser, unit.TypeCode) { ctx.Data["repo_template"] = templateID ctx.Data["repo_template_name"] = templateRepo.Name } @@ -223,7 +223,7 @@ func CreatePost(ctx *context.Context) { var repo *repo_model.Repository var err error if form.RepoTemplate > 0 { - opts := models.GenerateRepoOptions{ + opts := repo_module.GenerateRepoOptions{ Name: form.RepoName, Description: form.Description, Private: form.Private, @@ -304,7 +304,7 @@ func Action(ctx *context.Context) { ctx.Repo.Repository.Description = ctx.FormString("desc") ctx.Repo.Repository.Website = ctx.FormString("site") - err = models.UpdateRepository(ctx.Repo.Repository, false) + err = repo_service.UpdateRepository(ctx.Repo.Repository, false) } if err != nil { @@ -509,7 +509,7 @@ func InitiateDownload(ctx *context.Context) { // SearchRepo repositories via options func SearchRepo(ctx *context.Context) { - opts := &models.SearchRepoOptions{ + opts := &repo_model.SearchRepoOptions{ ListOptions: db.ListOptions{ Page: ctx.FormInt("page"), PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")), @@ -581,7 +581,7 @@ func SearchRepo(ctx *context.Context) { } var err error - repos, count, err := models.SearchRepository(opts) + repos, count, err := repo_model.SearchRepository(opts) if err != nil { ctx.JSON(http.StatusInternalServerError, api.SearchError{ OK: false, diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index a60bf52622..b7be0aa3f5 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -168,7 +168,7 @@ func SettingsPost(ctx *context.Context) { } repo.IsPrivate = form.Private - if err := models.UpdateRepository(repo, visibilityChanged); err != nil { + if err := repo_service.UpdateRepository(repo, visibilityChanged); err != nil { ctx.ServerError("UpdateRepository", err) return } @@ -491,7 +491,7 @@ func SettingsPost(ctx *context.Context) { return } if repoChanged { - if err := models.UpdateRepository(repo, false); err != nil { + if err := repo_service.UpdateRepository(repo, false); err != nil { ctx.ServerError("UpdateRepository", err) return } @@ -510,7 +510,7 @@ func SettingsPost(ctx *context.Context) { } if changed { - if err := models.UpdateRepository(repo, false); err != nil { + if err := repo_service.UpdateRepository(repo, false); err != nil { ctx.ServerError("UpdateRepository", err) return } @@ -530,7 +530,7 @@ func SettingsPost(ctx *context.Context) { repo.IsFsckEnabled = form.EnableHealthCheck } - if err := models.UpdateRepository(repo, false); err != nil { + if err := repo_service.UpdateRepository(repo, false); err != nil { ctx.ServerError("UpdateRepository", err) return } diff --git a/routers/web/repo/view.go b/routers/web/repo/view.go index 95ca81c442..2c9e16de5b 100644 --- a/routers/web/repo/view.go +++ b/routers/web/repo/view.go @@ -34,6 +34,7 @@ import ( "code.gitea.io/gitea/modules/lfs" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" + repo_module "code.gitea.io/gitea/modules/repository" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/typesniffer" @@ -905,7 +906,7 @@ func renderCode(ctx *context.Context) { ctx.ServerError("UpdateRepositoryCols", err) return } - if err = models.UpdateRepoSize(ctx, ctx.Repo.Repository); err != nil { + if err = repo_module.UpdateRepoSize(ctx, ctx.Repo.Repository); err != nil { ctx.ServerError("UpdateRepoSize", err) return } |