Skip to content

Commit

Permalink
Fix regression in PR-API #248 (#349)
Browse files Browse the repository at this point in the history
* Fix #344 (regression in PR-API #248)
  • Loading branch information
bkcsoft authored Dec 5, 2016
1 parent edae0f1 commit d07c955
Showing 1 changed file with 39 additions and 7 deletions.
46 changes: 39 additions & 7 deletions models/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,40 @@ func (pr *PullRequest) LoadIssue() (err error) {
// Required - Issue
// Optional - Merger
func (pr *PullRequest) APIFormat() *api.PullRequest {

var (
baseBranch *Branch
headBranch *Branch
baseCommit *git.Commit
headCommit *git.Commit
err error
)
apiIssue := pr.Issue.APIFormat()
baseBranch, _ := pr.BaseRepo.GetBranch(pr.BaseBranch)
baseCommit, _ := baseBranch.GetCommit()
headBranch, _ := pr.HeadRepo.GetBranch(pr.HeadBranch)
headCommit, _ := headBranch.GetCommit()
if pr.BaseRepo == nil {
pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID)
if err != nil {
log.Error(log.ERROR, "GetRepositoryById[%d]: %v", pr.ID, err)
return nil
}
}
if pr.HeadRepo == nil {
pr.HeadRepo, err = GetRepositoryByID(pr.HeadRepoID)
if err != nil {
log.Error(log.ERROR, "GetRepositoryById[%d]: %v", pr.ID, err)
return nil
}
}
if baseBranch, err = pr.BaseRepo.GetBranch(pr.BaseBranch); err != nil {
return nil
}
if baseCommit, err = baseBranch.GetCommit(); err != nil {
return nil
}
if headBranch, err = pr.HeadRepo.GetBranch(pr.HeadBranch); err != nil {
return nil
}
if headCommit, err = headBranch.GetCommit(); err != nil {
return nil
}
apiBaseBranchInfo := &api.PRBranchInfo{
Name: pr.BaseBranch,
Ref: pr.BaseBranch,
Expand Down Expand Up @@ -590,8 +618,12 @@ func GetPullRequestByIndex(repoID int64, index int64) (*PullRequest, error) {
return nil, ErrPullRequestNotExist{0, repoID, index, 0, "", ""}
}

pr.LoadAttributes()
pr.LoadIssue()
if err = pr.LoadAttributes(); err != nil {
return nil, err
}
if err = pr.LoadIssue(); err != nil {
return nil, err
}

return pr, nil
}
Expand Down

0 comments on commit d07c955

Please sign in to comment.