Fix pull request availability check
This commit is contained in:
parent
0ea0c5ec4f
commit
0e9bc2d410
|
@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
|
||||||
|
|
||||||
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
|
||||||
|
|
||||||
##### Current version: 0.9.0
|
##### Current version: 0.9.1
|
||||||
|
|
||||||
| Web | UI | Preview |
|
| Web | UI | Preview |
|
||||||
|:-------------:|:-------:|:-------:|
|
|:-------------:|:-------:|:-------:|
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.9.0.0306"
|
const APP_VER = "0.9.1.0306"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -27,6 +27,13 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PullRequestContext struct {
|
||||||
|
BaseRepo *models.Repository
|
||||||
|
Allowed bool
|
||||||
|
SameRepo bool
|
||||||
|
HeadInfo string // [<user>:]<branch>
|
||||||
|
}
|
||||||
|
|
||||||
type RepoContext struct {
|
type RepoContext struct {
|
||||||
AccessMode models.AccessMode
|
AccessMode models.AccessMode
|
||||||
IsWatching bool
|
IsWatching bool
|
||||||
|
@ -46,6 +53,8 @@ type RepoContext struct {
|
||||||
CloneLink models.CloneLink
|
CloneLink models.CloneLink
|
||||||
CommitsCount int64
|
CommitsCount int64
|
||||||
Mirror *models.Mirror
|
Mirror *models.Mirror
|
||||||
|
|
||||||
|
PullRequest *PullRequestContext
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context represents context of a request.
|
// Context represents context of a request.
|
||||||
|
@ -211,7 +220,9 @@ func Contexter() macaron.Handler {
|
||||||
csrf: x,
|
csrf: x,
|
||||||
Flash: f,
|
Flash: f,
|
||||||
Session: sess,
|
Session: sess,
|
||||||
Repo: &RepoContext{},
|
Repo: &RepoContext{
|
||||||
|
PullRequest: &PullRequestContext{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
// Compute current URL for real-time change language.
|
// Compute current URL for real-time change language.
|
||||||
ctx.Data["Link"] = setting.AppSubUrl + strings.TrimSuffix(ctx.Req.URL.Path, "/")
|
ctx.Data["Link"] = setting.AppSubUrl + strings.TrimSuffix(ctx.Req.URL.Path, "/")
|
||||||
|
|
|
@ -142,32 +142,6 @@ func RepoAssignment(args ...bool) macaron.Handler {
|
||||||
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
|
ctx.Data["IsRepositoryAdmin"] = ctx.Repo.IsAdmin()
|
||||||
ctx.Data["IsRepositoryWriter"] = ctx.Repo.IsWriter()
|
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["DisableSSH"] = setting.SSH.Disabled
|
||||||
ctx.Data["CloneLink"] = repo.CloneLink()
|
ctx.Data["CloneLink"] = repo.CloneLink()
|
||||||
ctx.Data["WikiCloneLink"] = repo.WikiCloneLink()
|
ctx.Data["WikiCloneLink"] = repo.WikiCloneLink()
|
||||||
|
@ -209,10 +183,41 @@ func RepoAssignment(args ...bool) macaron.Handler {
|
||||||
ctx.Repo.BranchName = brs[0]
|
ctx.Repo.BranchName = brs[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
ctx.Data["BranchName"] = ctx.Repo.BranchName
|
||||||
ctx.Data["CommitID"] = ctx.Repo.CommitID
|
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" {
|
if ctx.Query("go-get") == "1" {
|
||||||
ctx.Data["GoGetImport"] = path.Join(setting.Domain, setting.AppSubUrl, owner.Name, repo.Name)
|
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)
|
prefix := setting.AppUrl + path.Join(owner.Name, repo.Name, "src", ctx.Repo.BranchName)
|
||||||
|
|
|
@ -55,15 +55,21 @@ var (
|
||||||
func MustEnableIssues(ctx *middleware.Context) {
|
func MustEnableIssues(ctx *middleware.Context) {
|
||||||
if !ctx.Repo.Repository.EnableIssues {
|
if !ctx.Repo.Repository.EnableIssues {
|
||||||
ctx.Handle(404, "MustEnableIssues", nil)
|
ctx.Handle(404, "MustEnableIssues", nil)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func MustAllowPulls(ctx *middleware.Context) {
|
func MustAllowPulls(ctx *middleware.Context) {
|
||||||
if !ctx.Repo.Repository.AllowsPulls() {
|
if !ctx.Repo.Repository.AllowsPulls() {
|
||||||
ctx.Handle(404, "MustAllowPulls", nil)
|
ctx.Handle(404, "MustAllowPulls", nil)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["HasForkedRepo"] = ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)
|
// User can send pull request if owns a forked repository.
|
||||||
|
if ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID) {
|
||||||
|
ctx.Repo.PullRequest.Allowed = true
|
||||||
|
ctx.Repo.PullRequest.HeadInfo = ctx.User.Name + ":" + ctx.Repo.BranchName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RetrieveLabels(ctx *middleware.Context) {
|
func RetrieveLabels(ctx *middleware.Context) {
|
||||||
|
@ -560,14 +566,18 @@ func ViewIssue(ctx *middleware.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if issue.IsPull {
|
if issue.IsPull {
|
||||||
|
MustAllowPulls(ctx)
|
||||||
|
if ctx.Written() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Data["PageIsPullList"] = true
|
||||||
|
|
||||||
if err = issue.GetPullRequest(); err != nil {
|
if err = issue.GetPullRequest(); err != nil {
|
||||||
ctx.Handle(500, "GetPullRequest", err)
|
ctx.Handle(500, "GetPullRequest", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Data["PageIsPullList"] = true
|
|
||||||
ctx.Data["PageIsPullConversation"] = true
|
ctx.Data["PageIsPullConversation"] = true
|
||||||
ctx.Data["HasForkedRepo"] = ctx.IsSigned && ctx.User.HasForkedRepo(ctx.Repo.Repository.ID)
|
|
||||||
} else {
|
} else {
|
||||||
MustEnableIssues(ctx)
|
MustEnableIssues(ctx)
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
|
|
|
@ -462,7 +462,7 @@ func ParseCompareInfo(ctx *middleware.Context) (*models.User, *models.Repository
|
||||||
}
|
}
|
||||||
ctx.Data["HeadUser"] = headUser
|
ctx.Data["HeadUser"] = headUser
|
||||||
ctx.Data["HeadBranch"] = headBranch
|
ctx.Data["HeadBranch"] = headBranch
|
||||||
ctx.Data["IsBetweenBranches"] = isSameRepo
|
ctx.Repo.PullRequest.SameRepo = isSameRepo
|
||||||
|
|
||||||
// Check if base branch is valid.
|
// Check if base branch is valid.
|
||||||
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
|
if !ctx.Repo.GitRepo.IsBranchExist(baseBranch) {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.9.0.0306
|
0.9.1.0306
|
|
@ -7,9 +7,9 @@
|
||||||
<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
|
<a class="link" href="{{.Repository.Website}}">{{.Repository.Website}}</a>
|
||||||
</p>
|
</p>
|
||||||
<div class="ui secondary menu">
|
<div class="ui secondary menu">
|
||||||
{{if .CanPullRequest}}
|
{{if .PullRequestCtx.Allowed}}
|
||||||
<div class="fitted item">
|
<div class="fitted item">
|
||||||
<a href="{{.BaseRepo.RepoLink}}/compare/{{.BaseRepo.DefaultBranch}}...{{if not .IsBetweenBranches}}{{$.Owner.Name}}:{{end}}{{$.BranchName}}">
|
<a href="{{.BaseRepo.RepoLink}}/compare/{{.BaseRepo.DefaultBranch}}...{{.PullRequestCtx.HeadInfo}}">
|
||||||
<button class="ui green small button"><i class="octicon octicon-git-compare"></i></button>
|
<button class="ui green small button"><i class="octicon octicon-git-compare"></i></button>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
{{if .PageIsIssueList}}
|
{{if .PageIsIssueList}}
|
||||||
<a class="ui green button" href="{{.RepoLink}}/issues/new">{{.i18n.Tr "repo.issues.new"}}</a>
|
<a class="ui green button" href="{{.RepoLink}}/issues/new">{{.i18n.Tr "repo.issues.new"}}</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a class="ui green button {{if not (or .CanPullRequest .HasForkedRepo)}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.Repository.DefaultBranch}}...{{if not (eq .Owner.Name .SignedUserName)}}{{.SignedUserName}}:{{end}}{{.BranchName}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.Repository.DefaultBranch}}...{{.PullRequestCtx.HeadInfo}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
{{if .PageIsIssueList}}
|
{{if .PageIsIssueList}}
|
||||||
<a class="ui green button" href="{{.RepoLink}}/issues/new">{{.i18n.Tr "repo.issues.new"}}</a>
|
<a class="ui green button" href="{{.RepoLink}}/issues/new">{{.i18n.Tr "repo.issues.new"}}</a>
|
||||||
{{else}}
|
{{else}}
|
||||||
<a class="ui green button {{if not .HasForkedRepo}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.BranchName}}...{{.SignedUserName}}:{{.BranchName}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.BranchName}}...{{.PullRequestCtx.HeadInfo}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<div class="navbar">
|
<div class="navbar">
|
||||||
{{template "repo/issue/navbar" .}}
|
{{template "repo/issue/navbar" .}}
|
||||||
<div class="ui right">
|
<div class="ui right">
|
||||||
<a class="ui green button {{if not .HasForkedRepo}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.BranchName}}...{{.SignedUserName}}:{{.BranchName}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.BranchName}}...{{.PullRequestCtx.HeadInfo}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="scrolling menu">
|
<div class="scrolling menu">
|
||||||
{{range .Branches}}
|
{{range .Branches}}
|
||||||
<div class="item {{if eq $.BaseBranch .}}selected{{end}}" data-url="{{$.RepoLink}}/compare/{{.}}...{{if not $.IsBetweenBranches}}{{$.HeadUser.Name}}:{{end}}{{$.HeadBranch}}">{{.}}</div>
|
<div class="item {{if eq $.BaseBranch .}}selected{{end}}" data-url="{{$.RepoLink}}/compare/{{.}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}:{{end}}{{$.HeadBranch}}">{{.}}</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="scrolling menu">
|
<div class="scrolling menu">
|
||||||
{{range .HeadBranches}}
|
{{range .HeadBranches}}
|
||||||
<div class="{{if eq $.HeadBranch .}}selected{{end}} item" data-url="{{$.RepoLink}}/compare/{{$.BaseBranch}}...{{if not $.IsBetweenBranches}}{{$.HeadUser.Name}}:{{end}}{{.}}">{{.}}</div>
|
<div class="{{if eq $.HeadBranch .}}selected{{end}} item" data-url="{{$.RepoLink}}/compare/{{$.BaseBranch}}...{{if not $.PullRequestCtx.SameRepo}}{{$.HeadUser.Name}}:{{end}}{{.}}">{{.}}</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
<div class="navbar">
|
<div class="navbar">
|
||||||
{{template "repo/issue/navbar" .}}
|
{{template "repo/issue/navbar" .}}
|
||||||
<div class="ui right">
|
<div class="ui right">
|
||||||
<a class="ui green button {{if not .HasForkedRepo}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.BranchName}}...{{.SignedUserName}}:{{.BranchName}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
<a class="ui green button {{if not .PullRequestCtx.Allowed}}disabled{{end}}" href="{{.RepoLink}}/compare/{{.BranchName}}...{{.PullRequestCtx.HeadInfo}}">{{.i18n.Tr "repo.pulls.new"}}</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="ui divider"></div>
|
<div class="ui divider"></div>
|
||||||
|
|
Loading…
Reference in a new issue