aboutsummaryrefslogtreecommitdiffstats
path: root/routers/repo
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-10-26 14:54:11 +0800
committerGitHub <noreply@github.com>2019-10-26 14:54:11 +0800
commit9e85358777ea4bd345f832d08b19915a72cc128b (patch)
tree56116e7a6acbfd91a29cade7f753802f9ea561ea /routers/repo
parentd2d5910894cfe513f8aa331b30c991db6fbe8e6d (diff)
downloadgitea-9e85358777ea4bd345f832d08b19915a72cc128b.tar.gz
gitea-9e85358777ea4bd345f832d08b19915a72cc128b.zip
Move some repositories' operations to a standalone service package (#8557)
* Move some repositories' operations to a standalone service package * improve code * remove unused codes * add rollback when fork failed * add repo when return
Diffstat (limited to 'routers/repo')
-rw-r--r--routers/repo/pull.go3
-rw-r--r--routers/repo/repo.go12
-rw-r--r--routers/repo/setting.go3
3 files changed, 6 insertions, 12 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index 23d97e7b7e..f3a9aca2a4 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -26,6 +26,7 @@ import (
"code.gitea.io/gitea/services/gitdiff"
issue_service "code.gitea.io/gitea/services/issue"
pull_service "code.gitea.io/gitea/services/pull"
+ repo_service "code.gitea.io/gitea/services/repository"
"github.com/unknwon/com"
)
@@ -209,7 +210,7 @@ func ForkPost(ctx *context.Context, form auth.CreateRepoForm) {
}
}
- repo, err := models.ForkRepository(ctx.User, ctxUser, forkRepo, form.RepoName, form.Description)
+ repo, err := repo_service.ForkRepository(ctx.User, ctxUser, forkRepo, form.RepoName, form.Description)
if err != nil {
ctx.Data["Err_RepoName"] = true
switch {
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index bfd0c771b0..cf1845a727 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -17,10 +17,10 @@ import (
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/migrations"
- "code.gitea.io/gitea/modules/notification"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/task"
"code.gitea.io/gitea/modules/util"
+ repo_service "code.gitea.io/gitea/services/repository"
"github.com/unknwon/com"
)
@@ -170,7 +170,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
return
}
- repo, err := models.CreateRepository(ctx.User, ctxUser, models.CreateRepoOptions{
+ repo, err := repo_service.CreateRepository(ctx.User, ctxUser, models.CreateRepoOptions{
Name: form.RepoName,
Description: form.Description,
Gitignores: form.Gitignores,
@@ -181,19 +181,11 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) {
AutoInit: form.AutoInit,
})
if err == nil {
- notification.NotifyCreateRepository(ctx.User, ctxUser, repo)
-
log.Trace("Repository created [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)
ctx.Redirect(setting.AppSubURL + "/" + ctxUser.Name + "/" + repo.Name)
return
}
- if repo != nil {
- if errDelete := models.DeleteRepository(ctx.User, ctxUser.ID, repo.ID); errDelete != nil {
- log.Error("DeleteRepository: %v", errDelete)
- }
- }
-
handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form)
}
diff --git a/routers/repo/setting.go b/routers/repo/setting.go
index c74b273420..663394fe3d 100644
--- a/routers/repo/setting.go
+++ b/routers/repo/setting.go
@@ -26,6 +26,7 @@ import (
"code.gitea.io/gitea/routers/utils"
"code.gitea.io/gitea/services/mailer"
mirror_service "code.gitea.io/gitea/services/mirror"
+ repo_service "code.gitea.io/gitea/services/repository"
"github.com/unknwon/com"
"mvdan.cc/xurls/v2"
@@ -407,7 +408,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
return
}
- if err := models.DeleteRepository(ctx.User, ctx.Repo.Owner.ID, repo.ID); err != nil {
+ if err := repo_service.DeleteRepository(ctx.User, ctx.Repo.Repository); err != nil {
ctx.ServerError("DeleteRepository", err)
return
}