1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Move repository model into models/repo (#17933)

* Some refactors related repository model

* Move more methods out of repository

* Move repository into models/repo

* Fix test

* Fix test

* some improvements

* Remove unnecessary function
This commit is contained in:
Lunny Xiao
2021-12-10 09:27:50 +08:00
committed by GitHub
parent fb8166c6c6
commit 719bddcd76
301 changed files with 3193 additions and 2919 deletions

View File

@@ -9,6 +9,7 @@ import (
"errors"
"net/http"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/perm"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
@@ -48,13 +49,13 @@ func ListCollaborators(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/UserList"
count, err := ctx.Repo.Repository.CountCollaborators()
count, err := models.CountCollaborators(ctx.Repo.Repository.ID)
if err != nil {
ctx.InternalServerError(err)
return
}
collaborators, err := ctx.Repo.Repository.GetCollaborators(utils.GetListOptions(ctx))
collaborators, err := models.GetCollaborators(ctx.Repo.Repository.ID, utils.GetListOptions(ctx))
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
return
@@ -109,7 +110,7 @@ func IsCollaborator(ctx *context.APIContext) {
}
return
}
isColab, err := ctx.Repo.Repository.IsCollaborator(user.ID)
isColab, err := models.IsCollaborator(ctx.Repo.Repository.ID, user.ID)
if err != nil {
ctx.Error(http.StatusInternalServerError, "IsCollaborator", err)
return
@@ -171,13 +172,13 @@ func AddCollaborator(ctx *context.APIContext) {
return
}
if err := ctx.Repo.Repository.AddCollaborator(collaborator); err != nil {
if err := models.AddCollaborator(ctx.Repo.Repository, collaborator); err != nil {
ctx.Error(http.StatusInternalServerError, "AddCollaborator", err)
return
}
if form.Permission != nil {
if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, perm.ParseAccessMode(*form.Permission)); err != nil {
if err := models.ChangeCollaborationAccessMode(ctx.Repo.Repository, collaborator.ID, perm.ParseAccessMode(*form.Permission)); err != nil {
ctx.Error(http.StatusInternalServerError, "ChangeCollaborationAccessMode", err)
return
}
@@ -225,7 +226,7 @@ func DeleteCollaborator(ctx *context.APIContext) {
return
}
if err := ctx.Repo.Repository.DeleteCollaboration(collaborator.ID); err != nil {
if err := models.DeleteCollaboration(ctx.Repo.Repository, collaborator.ID); err != nil {
ctx.Error(http.StatusInternalServerError, "DeleteCollaboration", err)
return
}
@@ -254,7 +255,7 @@ func GetReviewers(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/UserList"
reviewers, err := ctx.Repo.Repository.GetReviewers(ctx.User.ID, 0)
reviewers, err := models.GetReviewers(ctx.Repo.Repository, ctx.User.ID, 0)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
return
@@ -284,7 +285,7 @@ func GetAssignees(ctx *context.APIContext) {
// "200":
// "$ref": "#/responses/UserList"
assignees, err := ctx.Repo.Repository.GetAssignees()
assignees, err := models.GetRepoAssignees(ctx.Repo.Repository)
if err != nil {
ctx.Error(http.StatusInternalServerError, "ListCollaborators", err)
return