summaryrefslogtreecommitdiffstats
path: root/routers/repo/pull.go
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2015-08-08 17:10:34 +0800
committerUnknwon <u@gogs.io>2015-08-08 17:10:34 +0800
commit9db4acc62e2d253c21ce9aed2e21003ff235d5b5 (patch)
tree1718b390dce8fb2e0771f4033cb1f6b24d66f0b3 /routers/repo/pull.go
parente6862e9cec49acf1cf8bbb5d1baee299a52b4967 (diff)
downloadgitea-9db4acc62e2d253c21ce9aed2e21003ff235d5b5.tar.gz
gitea-9db4acc62e2d253c21ce9aed2e21003ff235d5b5.zip
improve fork process
Diffstat (limited to 'routers/repo/pull.go')
-rw-r--r--routers/repo/pull.go95
1 files changed, 95 insertions, 0 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index d379a54eaa..cb5167033c 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -5,14 +5,109 @@
package repo
import (
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/auth"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
+ "github.com/gogits/gogs/modules/setting"
)
const (
+ FORK base.TplName = "repo/pulls/fork"
PULLS base.TplName = "repo/pulls"
)
+func getForkRepository(ctx *middleware.Context) *models.Repository {
+ forkRepo, err := models.GetRepositoryById(ctx.ParamsInt64(":repoid"))
+ if err != nil {
+ if models.IsErrRepoNotExist(err) {
+ ctx.Handle(404, "GetRepositoryById", nil)
+ } else {
+ ctx.Handle(500, "GetRepositoryById", err)
+ }
+ return nil
+ }
+ ctx.Data["repo_name"] = forkRepo.Name
+ ctx.Data["desc"] = forkRepo.Description
+ ctx.Data["IsPrivate"] = forkRepo.IsPrivate
+
+ if err = forkRepo.GetOwner(); err != nil {
+ ctx.Handle(500, "GetOwner", err)
+ return nil
+ }
+ ctx.Data["ForkFrom"] = forkRepo.Owner.Name + "/" + forkRepo.Name
+
+ if err := ctx.User.GetOrganizations(); err != nil {
+ ctx.Handle(500, "GetOrganizations", err)
+ return nil
+ }
+ ctx.Data["Orgs"] = ctx.User.Orgs
+
+ return forkRepo
+}
+
+func Fork(ctx *middleware.Context) {
+ ctx.Data["Title"] = ctx.Tr("new_fork")
+
+ getForkRepository(ctx)
+ if ctx.Written() {
+ return
+ }
+
+ ctx.Data["ContextUser"] = ctx.User
+ ctx.HTML(200, FORK)
+}
+
+func ForkPost(ctx *middleware.Context, form auth.CreateRepoForm) {
+ ctx.Data["Title"] = ctx.Tr("new_fork")
+
+ forkRepo := getForkRepository(ctx)
+ if ctx.Written() {
+ return
+ }
+
+ ctxUser := checkContextUser(ctx, form.Uid)
+ if ctx.Written() {
+ return
+ }
+ ctx.Data["ContextUser"] = ctxUser
+
+ if ctx.HasError() {
+ ctx.HTML(200, FORK)
+ return
+ }
+
+ // Check ownership of organization.
+ if ctxUser.IsOrganization() {
+ if !ctxUser.IsOwnedBy(ctx.User.Id) {
+ ctx.Error(403)
+ return
+ }
+ }
+
+ repo, err := models.ForkRepository(ctxUser, forkRepo, form.RepoName, form.Description)
+ if err != nil {
+ switch {
+ case models.IsErrRepoAlreadyExist(err):
+ ctx.Data["Err_RepoName"] = true
+ ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), FORK, &form)
+ case models.IsErrNameReserved(err):
+ ctx.Data["Err_RepoName"] = true
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(models.ErrNameReserved).Name), FORK, &form)
+ case models.IsErrNamePatternNotAllowed(err):
+ ctx.Data["Err_RepoName"] = true
+ ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), FORK, &form)
+ default:
+ ctx.Handle(500, "ForkPost", err)
+ }
+ return
+ }
+
+ log.Trace("Repository forked[%d]: %s/%s", forkRepo.Id, ctxUser.Name, repo.Name)
+ ctx.Redirect(setting.AppSubUrl + "/" + ctxUser.Name + "/" + repo.Name)
+}
+
func Pulls(ctx *middleware.Context) {
ctx.Data["IsRepoToolbarPulls"] = true
ctx.HTML(200, PULLS)