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/api/v1 | |
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/api/v1')
-rw-r--r-- | routers/api/v1/repo/collaborators.go | 4 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 7 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 10 | ||||
-rw-r--r-- | routers/api/v1/user/repo.go | 8 |
4 files changed, 15 insertions, 14 deletions
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go index 248497a561..aa425e5828 100644 --- a/routers/api/v1/repo/collaborators.go +++ b/routers/api/v1/repo/collaborators.go @@ -312,7 +312,7 @@ func GetReviewers(ctx *context.APIContext) { // "200": // "$ref": "#/responses/UserList" - reviewers, err := models.GetReviewers(ctx.Repo.Repository, ctx.Doer.ID, 0) + reviewers, err := repo_model.GetReviewers(ctx, ctx.Repo.Repository, ctx.Doer.ID, 0) if err != nil { ctx.Error(http.StatusInternalServerError, "ListCollaborators", err) return @@ -342,7 +342,7 @@ func GetAssignees(ctx *context.APIContext) { // "200": // "$ref": "#/responses/UserList" - assignees, err := models.GetRepoAssignees(ctx.Repo.Repository) + assignees, err := repo_model.GetRepoAssignees(ctx, ctx.Repo.Repository) if err != nil { ctx.Error(http.StatusInternalServerError, "ListCollaborators", err) return diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 62959c3a76..c394ad1756 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -17,6 +17,7 @@ import ( issues_model "code.gitea.io/gitea/models/issues" "code.gitea.io/gitea/models/organization" access_model "code.gitea.io/gitea/models/perm/access" + repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unit" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/context" @@ -130,7 +131,7 @@ func SearchIssues(ctx *context.APIContext) { } // find repos user can access (for issue search) - opts := &models.SearchRepoOptions{ + opts := &repo_model.SearchRepoOptions{ Private: false, AllPublic: true, TopicOnly: false, @@ -176,8 +177,8 @@ func SearchIssues(ctx *context.APIContext) { 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) return diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 8485ffbac2..cdd1f7d5c4 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -123,7 +123,7 @@ func Search(ctx *context.APIContext) { // "422": // "$ref": "#/responses/validationError" - opts := &models.SearchRepoOptions{ + opts := &repo_model.SearchRepoOptions{ ListOptions: utils.GetListOptions(ctx), Actor: ctx.Doer, Keyword: ctx.FormTrim("q"), @@ -192,7 +192,7 @@ func Search(ctx *context.APIContext) { } 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, @@ -344,7 +344,7 @@ func Generate(ctx *context.APIContext) { return } - opts := models.GenerateRepoOptions{ + opts := repo_module.GenerateRepoOptions{ Name: form.Name, DefaultBranch: form.DefaultBranch, Description: form.Description, @@ -717,7 +717,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err repo.DefaultBranch = *opts.DefaultBranch } - if err := models.UpdateRepository(repo, visibilityChanged); err != nil { + if err := repo_service.UpdateRepository(repo, visibilityChanged); err != nil { ctx.Error(http.StatusInternalServerError, "UpdateRepository", err) return err } @@ -1036,7 +1036,7 @@ func Delete(ctx *context.APIContext) { owner := ctx.Repo.Owner repo := ctx.Repo.Repository - canDelete, err := models.CanUserDelete(repo, ctx.Doer) + canDelete, err := repo_module.CanUserDelete(repo, ctx.Doer) if err != nil { ctx.Error(http.StatusInternalServerError, "CanUserDelete", err) return diff --git a/routers/api/v1/user/repo.go b/routers/api/v1/user/repo.go index 05cecf508b..709e3a6c54 100644 --- a/routers/api/v1/user/repo.go +++ b/routers/api/v1/user/repo.go @@ -7,9 +7,9 @@ package user import ( "net/http" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/perm" access_model "code.gitea.io/gitea/models/perm/access" + 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" @@ -21,7 +21,7 @@ import ( func listUserRepos(ctx *context.APIContext, u *user_model.User, private bool) { opts := utils.GetListOptions(ctx) - repos, count, err := models.GetUserRepositories(&models.SearchRepoOptions{ + repos, count, err := repo_model.GetUserRepositories(&repo_model.SearchRepoOptions{ Actor: u, Private: private, ListOptions: opts, @@ -103,7 +103,7 @@ func ListMyRepos(ctx *context.APIContext) { // "200": // "$ref": "#/responses/RepositoryList" - opts := &models.SearchRepoOptions{ + opts := &repo_model.SearchRepoOptions{ ListOptions: utils.GetListOptions(ctx), Actor: ctx.Doer, OwnerID: ctx.Doer.ID, @@ -112,7 +112,7 @@ func ListMyRepos(ctx *context.APIContext) { } var err error - repos, count, err := models.SearchRepository(opts) + repos, count, err := repo_model.SearchRepository(opts) if err != nil { ctx.Error(http.StatusInternalServerError, "SearchRepository", err) return |