From d4dbe3891d4ea5baa9db97c8bc1994410c91c4c2 Mon Sep 17 00:00:00 2001 From: Kazuki Sawada Date: Tue, 3 Oct 2017 17:04:34 +0900 Subject: [PATCH 1/3] Change pull description text --- routers/repo/pull.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 87d3bdc26db6..f1707b3de086 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -182,11 +182,17 @@ func checkPullInfo(ctx *context.Context) *models.Issue { // PrepareMergedViewPullInfo show meta information for a merged pull request view page func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) { pull := issue.PullRequest - ctx.Data["HasMerged"] = true - ctx.Data["HeadTarget"] = issue.PullRequest.HeadUserName + "/" + pull.HeadBranch - ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch var err error + if err = pull.GetHeadRepo(); err != nil { + ctx.Handle(500, "GetHeadRepo", err) + return + } + + ctx.Data["HasMerged"] = true + ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + ctx.Data["BaseTarget"] = pull.BaseBranch + ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID) if err != nil { ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err) @@ -204,19 +210,16 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq repo := ctx.Repo.Repository pull := issue.PullRequest - ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadBranch - ctx.Data["BaseTarget"] = ctx.Repo.Owner.Name + "/" + pull.BaseBranch - - var ( - headGitRepo *git.Repository - err error - ) - + var err error if err = pull.GetHeadRepo(); err != nil { ctx.Handle(500, "GetHeadRepo", err) return nil } + ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + ctx.Data["BaseTarget"] = pull.BaseBranch + + var headGitRepo *git.Repository if pull.HeadRepo != nil { headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath()) if err != nil { From b6c79335e416784e15a9d0b4f7c2960ee0fc9be6 Mon Sep 17 00:00:00 2001 From: Kazuki Sawada Date: Thu, 5 Oct 2017 00:52:10 +0900 Subject: [PATCH 2/3] avoid panic / show branch name only (in same repository pullreq) --- routers/repo/pull.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index f1707b3de086..a1f76727840b 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -189,9 +189,15 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) { return } - ctx.Data["HasMerged"] = true - ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + if ctx.Repo.Owner.Name == pull.HeadUserName { + ctx.Data["HeadTarget"] = pull.HeadBranch + } else if pull.HeadRepo == nil { + ctx.Data["HeadTarget"] = pull.HeadUserName + ":" + pull.HeadBranch + } else { + ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + } ctx.Data["BaseTarget"] = pull.BaseBranch + ctx.Data["HasMerged"] = true ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID) if err != nil { @@ -216,7 +222,13 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq return nil } - ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + if ctx.Repo.Owner.Name == pull.HeadUserName { + ctx.Data["HeadTarget"] = pull.HeadBranch + } else if pull.HeadRepo == nil { + ctx.Data["HeadTarget"] = pull.HeadUserName + ":" + pull.HeadBranch + } else { + ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + } ctx.Data["BaseTarget"] = pull.BaseBranch var headGitRepo *git.Repository From 10d075f9410bcfbae8303c6bfa362e3c6fc17e74 Mon Sep 17 00:00:00 2001 From: Kazuki Sawada Date: Thu, 5 Oct 2017 01:49:36 +0900 Subject: [PATCH 3/3] move duplicated code into helper function --- routers/repo/pull.go | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/routers/repo/pull.go b/routers/repo/pull.go index a1f76727840b..48e17665dac3 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -179,6 +179,17 @@ func checkPullInfo(ctx *context.Context) *models.Issue { return issue } +func setMergeTarget(ctx *context.Context, pull *models.PullRequest) { + if ctx.Repo.Owner.Name == pull.HeadUserName { + ctx.Data["HeadTarget"] = pull.HeadBranch + } else if pull.HeadRepo == nil { + ctx.Data["HeadTarget"] = pull.HeadUserName + ":" + pull.HeadBranch + } else { + ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch + } + ctx.Data["BaseTarget"] = pull.BaseBranch +} + // PrepareMergedViewPullInfo show meta information for a merged pull request view page func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) { pull := issue.PullRequest @@ -189,14 +200,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) { return } - if ctx.Repo.Owner.Name == pull.HeadUserName { - ctx.Data["HeadTarget"] = pull.HeadBranch - } else if pull.HeadRepo == nil { - ctx.Data["HeadTarget"] = pull.HeadUserName + ":" + pull.HeadBranch - } else { - ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch - } - ctx.Data["BaseTarget"] = pull.BaseBranch + setMergeTarget(ctx, pull) ctx.Data["HasMerged"] = true ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID) @@ -222,14 +226,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.PullReq return nil } - if ctx.Repo.Owner.Name == pull.HeadUserName { - ctx.Data["HeadTarget"] = pull.HeadBranch - } else if pull.HeadRepo == nil { - ctx.Data["HeadTarget"] = pull.HeadUserName + ":" + pull.HeadBranch - } else { - ctx.Data["HeadTarget"] = pull.HeadUserName + "/" + pull.HeadRepo.Name + ":" + pull.HeadBranch - } - ctx.Data["BaseTarget"] = pull.BaseBranch + setMergeTarget(ctx, pull) var headGitRepo *git.Repository if pull.HeadRepo != nil {