aboutsummaryrefslogtreecommitdiffstats
path: root/models/pull.go
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2016-12-05 12:17:39 +0100
committerGitHub <noreply@github.com>2016-12-05 12:17:39 +0100
commitd07c955e2a6359937ecff458d450e328861da5e6 (patch)
treef99acc77963de11d1261ba55cc209964485010d9 /models/pull.go
parentedae0f134c2001119719f36a20ac8b1496f8d3a5 (diff)
downloadgitea-d07c955e2a6359937ecff458d450e328861da5e6.tar.gz
gitea-d07c955e2a6359937ecff458d450e328861da5e6.zip
Fix regression in PR-API #248 (#349)
* Fix #344 (regression in PR-API #248)
Diffstat (limited to 'models/pull.go')
-rw-r--r--models/pull.go46
1 files changed, 39 insertions, 7 deletions
diff --git a/models/pull.go b/models/pull.go
index 5b54058b8d..d149a142d0 100644
--- a/models/pull.go
+++ b/models/pull.go
@@ -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,
@@ -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
}