diff options
author | Unknwon <u@gogs.io> | 2016-03-06 23:57:46 -0500 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-03-06 23:57:46 -0500 |
commit | 0e9bc2d4108ae32611e4fe65af493913c20d0279 (patch) | |
tree | 58addb3ebbc98174543f5fc44bd60599941e3dd1 /modules/middleware | |
parent | 0ea0c5ec4f24f0fc5ef3231085c74b33a16f98ec (diff) | |
download | gitea-0e9bc2d4108ae32611e4fe65af493913c20d0279.tar.gz gitea-0e9bc2d4108ae32611e4fe65af493913c20d0279.zip |
Fix pull request availability check
Diffstat (limited to 'modules/middleware')
-rw-r--r-- | modules/middleware/context.go | 13 | ||||
-rw-r--r-- | modules/middleware/repo.go | 59 |
2 files changed, 44 insertions, 28 deletions
diff --git a/modules/middleware/context.go b/modules/middleware/context.go index cee5d10032..d2b7de4a27 100644 --- a/modules/middleware/context.go +++ b/modules/middleware/context.go @@ -27,6 +27,13 @@ import ( "github.com/gogits/gogs/modules/setting" ) +type PullRequestContext struct { + BaseRepo *models.Repository + Allowed bool + SameRepo bool + HeadInfo string // [<user>:]<branch> +} + type RepoContext struct { AccessMode models.AccessMode IsWatching bool @@ -46,6 +53,8 @@ type RepoContext struct { CloneLink models.CloneLink CommitsCount int64 Mirror *models.Mirror + + PullRequest *PullRequestContext } // Context represents context of a request. @@ -211,7 +220,9 @@ func Contexter() macaron.Handler { csrf: x, Flash: f, Session: sess, - Repo: &RepoContext{}, + Repo: &RepoContext{ + PullRequest: &PullRequestContext{}, + }, } // Compute current URL for real-time change language. ctx.Data["Link"] = setting.AppSubUrl + strings.TrimSuffix(ctx.Req.URL.Path, "/") diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 3e1835f5c9..f96b87d437 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -142,32 +142,6 @@ func RepoAssignment(args ...bool) macaron.Handler { ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin() ctx.Data["IsRepositoryWriter"] = ctx.Repo.IsWriter() - if repo.IsFork { - RetrieveBaseRepo(ctx, repo) - if ctx.Written() { - return - } - } - - // People who have push access and propose a new pull request. - if ctx.Repo.IsWriter() { - // Pull request is allowed if this is a fork repository - // and base repository accepts pull requests. - if repo.BaseRepo != nil { - if repo.BaseRepo.AllowsPulls() { - ctx.Data["CanPullRequest"] = true - ctx.Data["BaseRepo"] = repo.BaseRepo - } - } else { - // Or, this is repository accepts pull requests between branches. - if repo.AllowsPulls() { - ctx.Data["CanPullRequest"] = true - ctx.Data["BaseRepo"] = repo - ctx.Data["IsBetweenBranches"] = true - } - } - } - ctx.Data["DisableSSH"] = setting.SSH.Disabled ctx.Data["CloneLink"] = repo.CloneLink() ctx.Data["WikiCloneLink"] = repo.WikiCloneLink() @@ -209,10 +183,41 @@ func RepoAssignment(args ...bool) macaron.Handler { ctx.Repo.BranchName = brs[0] } } - ctx.Data["BranchName"] = ctx.Repo.BranchName ctx.Data["CommitID"] = ctx.Repo.CommitID + if repo.IsFork { + RetrieveBaseRepo(ctx, repo) + if ctx.Written() { + return + } + } + + // People who have push access and propose a new pull request. + if ctx.Repo.IsWriter() { + // Pull request is allowed if this is a fork repository + // and base repository accepts pull requests. + if repo.BaseRepo != nil { + if repo.BaseRepo.AllowsPulls() { + ctx.Data["BaseRepo"] = repo.BaseRepo + ctx.Repo.PullRequest.BaseRepo = repo.BaseRepo + ctx.Repo.PullRequest.Allowed = true + ctx.Repo.PullRequest.HeadInfo = ctx.Repo.Owner.Name + ":" + ctx.Repo.BranchName + } + } else { + // Or, this is repository accepts pull requests between branches. + if repo.AllowsPulls() { + ctx.Data["BaseRepo"] = repo + ctx.Repo.PullRequest.BaseRepo = repo + ctx.Repo.PullRequest.Allowed = true + ctx.Repo.PullRequest.SameRepo = true + ctx.Repo.PullRequest.HeadInfo = ctx.Repo.BranchName + } + } + } + fmt.Println(222222, ctx.Repo.PullRequest) + ctx.Data["PullRequestCtx"] = ctx.Repo.PullRequest + if ctx.Query("go-get") == "1" { ctx.Data["GoGetImport"] = path.Join(setting.Domain, setting.AppSubUrl, owner.Name, repo.Name) prefix := setting.AppUrl + path.Join(owner.Name, repo.Name, "src", ctx.Repo.BranchName) |