Browse Source

editor: fix cannot redirect to correct pull request URL

Was only possible to correctly redirect to pull request page within
same repository. And didn't take care of case when upstream has
disabled pull request.

Also add a new method 'PullRequestURL' to unify the code.
pull/3854/merge
Unknwon 8 years ago
parent
commit
5ec21d56ef
No known key found for this signature in database
GPG Key ID: 25B575AE3213B2B3
  1. 10
      modules/context/repo.go
  2. 12
      routers/repo/editor.go

10
modules/context/repo.go

@ -98,6 +98,16 @@ func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) {
return editorconfig.ParseBytes(data) return editorconfig.ParseBytes(data)
} }
// PullRequestURL returns URL for composing a pull request.
// This function does not check if the repository can actually compose a pull request.
func (r *Repository) PullRequestURL(baseBranch, headBranch string) string {
repoLink := r.RepoLink
if r.PullRequest.BaseRepo != nil {
repoLink = r.PullRequest.BaseRepo.Link()
}
return fmt.Sprintf("%s/compare/%s...%s:%s", repoLink, baseBranch, r.Owner.Name, headBranch)
}
func RetrieveBaseRepo(ctx *Context, repo *models.Repository) { func RetrieveBaseRepo(ctx *Context, repo *models.Repository) {
// Non-fork repository will not return error in this method. // Non-fork repository will not return error in this method.
if err := repo.GetBaseRepo(); err != nil { if err := repo.GetBaseRepo(); err != nil {

12
routers/repo/editor.go

@ -279,8 +279,8 @@ func editFilePost(ctx *context.Context, form auth.EditRepoFileForm, isNewFile bo
return return
} }
if form.IsNewBrnach() { if form.IsNewBrnach() && ctx.Repo.PullRequest.Allowed {
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName) ctx.Redirect(ctx.Repo.PullRequestURL(oldBranchName, form.NewBranchName))
} else { } else {
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + template.EscapePound(form.TreePath)) ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + template.EscapePound(form.TreePath))
} }
@ -382,8 +382,8 @@ func DeleteFilePost(ctx *context.Context, form auth.DeleteRepoFileForm) {
return return
} }
if form.IsNewBrnach() { if form.IsNewBrnach() && ctx.Repo.PullRequest.Allowed {
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName) ctx.Redirect(ctx.Repo.PullRequestURL(oldBranchName, form.NewBranchName))
} else { } else {
ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath)) ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", ctx.Repo.TreePath))
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName) ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName)
@ -503,8 +503,8 @@ func UploadFilePost(ctx *context.Context, form auth.UploadRepoFileForm) {
return return
} }
if form.IsNewBrnach() { if form.IsNewBrnach() && ctx.Repo.PullRequest.Allowed {
ctx.Redirect(ctx.Repo.RepoLink + "/compare/" + oldBranchName + "..." + form.NewBranchName) ctx.Redirect(ctx.Repo.PullRequestURL(oldBranchName, form.NewBranchName))
} else { } else {
ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + form.TreePath) ctx.Redirect(ctx.Repo.RepoLink + "/src/" + branchName + "/" + form.TreePath)
} }

Loading…
Cancel
Save