Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display pull request head branch even the branch deleted or repository deleted #10413

Merged
merged 7 commits into from
Mar 2, 2020
Next Next commit
Display pull request head branch even the branch deleted or repositor…
…y deleted
  • Loading branch information
lunny committed Feb 23, 2020
commit f386cca7f00b422826ff45e1133f2097c338559b
14 changes: 11 additions & 3 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
ctx.Data["IsPullRequestBroken"] = true
ctx.Data["BaseTarget"] = "deleted"
ctx.Data["BaseTarget"] = pull.BaseBranch
ctx.Data["NumCommits"] = 0
ctx.Data["NumFiles"] = 0
return nil
Expand Down Expand Up @@ -432,15 +432,23 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare

if pull.HeadRepo == nil || !headBranchExist || headBranchSha != sha {
ctx.Data["IsPullRequestBroken"] = true
ctx.Data["HeadTarget"] = "deleted"
if pull.IsSameRepo() {
ctx.Data["HeadTarget"] = pull.HeadBranch
} else {
if pull.HeadRepo == nil {
ctx.Data["HeadTarget"] = "<deleted>:" + pull.HeadBranch
} else {
ctx.Data["HeadTarget"] = pull.HeadRepo.OwnerName + ":" + pull.HeadBranch
}
}
}

compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
pull.BaseBranch, pull.GetGitRefName())
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
ctx.Data["IsPullRequestBroken"] = true
ctx.Data["BaseTarget"] = "deleted"
ctx.Data["BaseTarget"] = pull.BaseBranch
ctx.Data["NumCommits"] = 0
ctx.Data["NumFiles"] = 0
return nil
Expand Down