diff options
author | Kazuki Sawada <kazuki@6715.jp> | 2017-10-05 02:35:01 +0900 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2017-10-04 20:35:01 +0300 |
commit | e1266a19c847600aceee6f16875e0384c7c0f736 (patch) | |
tree | 4790adb857f5b257d82b426a756016564d179ffc | |
parent | fcca037576bc55b59a37d788213c64192f86b5b4 (diff) | |
download | gitea-e1266a19c847600aceee6f16875e0384c7c0f736.tar.gz gitea-e1266a19c847600aceee6f16875e0384c7c0f736.zip |
Change pull description text (#2075) (#2646)
* Change pull description text
* move duplicated code into helper function
-rw-r--r-- | routers/repo/pull.go | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go index 87d3bdc26d..48e17665da 100644 --- a/routers/repo/pull.go +++ b/routers/repo/pull.go @@ -179,14 +179,30 @@ 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 - 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 + } + + setMergeTarget(ctx, pull) + ctx.Data["HasMerged"] = true + ctx.Data["NumCommits"], err = ctx.Repo.GitRepo.CommitsCountBetween(pull.MergeBase, pull.MergedCommitID) if err != nil { ctx.Handle(500, "Repo.GitRepo.CommitsCountBetween", err) @@ -204,19 +220,15 @@ 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 } + setMergeTarget(ctx, pull) + + var headGitRepo *git.Repository if pull.HeadRepo != nil { headGitRepo, err = git.OpenRepository(pull.HeadRepo.RepoPath()) if err != nil { |