summaryrefslogtreecommitdiffstats
path: root/routers/private
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2021-12-10 09:27:50 +0800
committerGitHub <noreply@github.com>2021-12-10 09:27:50 +0800
commit719bddcd76610a63dadc8555760072957a11cf30 (patch)
tree0df26092fba7e3e21444fe493e6b349473b6b0cb /routers/private
parentfb8166c6c6b652a0e6fa98681780a6a71090faf3 (diff)
downloadgitea-719bddcd76610a63dadc8555760072957a11cf30.tar.gz
gitea-719bddcd76610a63dadc8555760072957a11cf30.zip
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
Diffstat (limited to 'routers/private')
-rw-r--r--routers/private/default_branch.go6
-rw-r--r--routers/private/hook_post_receive.go5
-rw-r--r--routers/private/hook_pre_receive.go2
-rw-r--r--routers/private/internal_repo.go6
-rw-r--r--routers/private/serv.go7
5 files changed, 14 insertions, 12 deletions
diff --git a/routers/private/default_branch.go b/routers/private/default_branch.go
index ec6adc4805..974534c219 100644
--- a/routers/private/default_branch.go
+++ b/routers/private/default_branch.go
@@ -9,7 +9,7 @@ import (
"fmt"
"net/http"
- "code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -34,7 +34,7 @@ func SetDefaultBranch(ctx *gitea_context.PrivateContext) {
ownerName := ctx.Params(":owner")
repoName := ctx.Params(":repo")
branch := ctx.Params(":branch")
- repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
+ repo, err := repo_model.GetRepositoryByOwnerAndName(ownerName, repoName)
if err != nil {
log.Error("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err)
ctx.JSON(http.StatusInternalServerError, private.Response{
@@ -65,7 +65,7 @@ func SetDefaultBranch(ctx *gitea_context.PrivateContext) {
}
gitRepo.Close()
- if err := repo.UpdateDefaultBranch(); err != nil {
+ if err := repo_model.UpdateDefaultBranch(repo); err != nil {
ctx.JSON(http.StatusInternalServerError, private.Response{
Err: fmt.Sprintf("Unable to set default branch on repository: %s/%s Error: %v", ownerName, repoName, err),
})
diff --git a/routers/private/hook_post_receive.go b/routers/private/hook_post_receive.go
index 0d559250ea..a71f465911 100644
--- a/routers/private/hook_post_receive.go
+++ b/routers/private/hook_post_receive.go
@@ -11,6 +11,7 @@ import (
"strings"
"code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -35,7 +36,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
repoName := ctx.Params(":repo")
// defer getting the repository at this point - as we should only retrieve it if we're going to call update
- var repo *models.Repository
+ var repo *repo_model.Repository
updates := make([]*repo_module.PushUpdateOptions, 0, len(opts.OldCommitIDs))
wasEmpty := false
@@ -116,7 +117,7 @@ func HookPostReceive(ctx *gitea_context.PrivateContext) {
// We have to reload the repo in case its state is changed above
repo = nil
- var baseRepo *models.Repository
+ var baseRepo *repo_model.Repository
// Now handle the pull request notification trailers
for i := range opts.OldCommitIDs {
diff --git a/routers/private/hook_pre_receive.go b/routers/private/hook_pre_receive.go
index 5ab21d525b..17ccf010ae 100644
--- a/routers/private/hook_pre_receive.go
+++ b/routers/private/hook_pre_receive.go
@@ -363,7 +363,7 @@ func preReceiveTag(ctx *preReceiveContext, oldCommitID, newCommitID, refFullName
if !ctx.gotProtectedTags {
var err error
- ctx.protectedTags, err = ctx.Repo.Repository.GetProtectedTags()
+ ctx.protectedTags, err = models.GetProtectedTags(ctx.Repo.Repository.ID)
if err != nil {
log.Error("Unable to get protected tags for %-v Error: %v", ctx.Repo.Repository, err)
ctx.JSON(http.StatusInternalServerError, private.Response{
diff --git a/routers/private/internal_repo.go b/routers/private/internal_repo.go
index 60daa1dbea..8d0fd72235 100644
--- a/routers/private/internal_repo.go
+++ b/routers/private/internal_repo.go
@@ -10,7 +10,7 @@ import (
"fmt"
"net/http"
- "code.gitea.io/gitea/models"
+ repo_model "code.gitea.io/gitea/models/repo"
gitea_context "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
@@ -68,8 +68,8 @@ func RepoAssignment(ctx *gitea_context.PrivateContext) context.CancelFunc {
return cancel
}
-func loadRepository(ctx *gitea_context.PrivateContext, ownerName, repoName string) *models.Repository {
- repo, err := models.GetRepositoryByOwnerAndName(ownerName, repoName)
+func loadRepository(ctx *gitea_context.PrivateContext, ownerName, repoName string) *repo_model.Repository {
+ repo, err := repo_model.GetRepositoryByOwnerAndName(ownerName, repoName)
if err != nil {
log.Error("Failed to get repository: %s/%s Error: %v", ownerName, repoName, err)
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
diff --git a/routers/private/serv.go b/routers/private/serv.go
index 9cbd0c2c82..f28d5a7450 100644
--- a/routers/private/serv.go
+++ b/routers/private/serv.go
@@ -12,6 +12,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/perm"
+ 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"
@@ -126,9 +127,9 @@ func ServCommand(ctx *context.PrivateContext) {
// Now get the Repository and set the results section
repoExist := true
- repo, err := models.GetRepositoryByName(owner.ID, results.RepoName)
+ repo, err := repo_model.GetRepositoryByName(owner.ID, results.RepoName)
if err != nil {
- if models.IsErrRepoNotExist(err) {
+ if repo_model.IsErrRepoNotExist(err) {
repoExist = false
for _, verb := range ctx.FormStrings("verb") {
if "git-upload-pack" == verb {
@@ -374,7 +375,7 @@ func ServCommand(ctx *context.PrivateContext) {
if results.IsWiki {
// Ensure the wiki is enabled before we allow access to it
if _, err := repo.GetUnit(unit.TypeWiki); err != nil {
- if models.IsErrUnitTypeNotExist(err) {
+ if repo_model.IsErrUnitTypeNotExist(err) {
ctx.JSON(http.StatusForbidden, private.ErrServCommand{
Results: results,
Err: "repository wiki is disabled",