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

Change pull description text (#2075) #2646

Merged
merged 4 commits into from
Oct 4, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If PR is made and than forked repository is deleted there will be error ErrRepoNotExist and it will not be possible to open PR even to close it. It should at least fall back to message ... from fork_owner:branch into branch format in such case.
Currently in such case this codes gets PANIC: runtime error: invalid memory address or nil pointer dereference

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I could be wrong that it returns error.., More looks like it just sets pull.HeadRepo as 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)
Expand All @@ -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 {
Expand Down