From 5ec21d56ef2a002327b705ede5adabe3f1f13f34 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Thu, 23 Feb 2017 13:05:29 -0500 Subject: 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. --- modules/context/repo.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'modules') diff --git a/modules/context/repo.go b/modules/context/repo.go index 710cbbf6..fdde6b92 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -98,6 +98,16 @@ func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error) { 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) { // Non-fork repository will not return error in this method. if err := repo.GetBaseRepo(); err != nil { -- cgit v1.2.3