|
|
@ -121,12 +121,40 @@ func (pr *PullRequest) LoadIssue() (err error) { |
|
|
|
// Required - Issue
|
|
|
|
// Required - Issue
|
|
|
|
// Optional - Merger
|
|
|
|
// Optional - Merger
|
|
|
|
func (pr *PullRequest) APIFormat() *api.PullRequest { |
|
|
|
func (pr *PullRequest) APIFormat() *api.PullRequest { |
|
|
|
|
|
|
|
var ( |
|
|
|
|
|
|
|
baseBranch *Branch |
|
|
|
|
|
|
|
headBranch *Branch |
|
|
|
|
|
|
|
baseCommit *git.Commit |
|
|
|
|
|
|
|
headCommit *git.Commit |
|
|
|
|
|
|
|
err error |
|
|
|
|
|
|
|
) |
|
|
|
apiIssue := pr.Issue.APIFormat() |
|
|
|
apiIssue := pr.Issue.APIFormat() |
|
|
|
baseBranch, _ := pr.BaseRepo.GetBranch(pr.BaseBranch) |
|
|
|
if pr.BaseRepo == nil { |
|
|
|
baseCommit, _ := baseBranch.GetCommit() |
|
|
|
pr.BaseRepo, err = GetRepositoryByID(pr.BaseRepoID) |
|
|
|
headBranch, _ := pr.HeadRepo.GetBranch(pr.HeadBranch) |
|
|
|
if err != nil { |
|
|
|
headCommit, _ := headBranch.GetCommit() |
|
|
|
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{ |
|
|
|
apiBaseBranchInfo := &api.PRBranchInfo{ |
|
|
|
Name: pr.BaseBranch, |
|
|
|
Name: pr.BaseBranch, |
|
|
|
Ref: pr.BaseBranch, |
|
|
|
Ref: pr.BaseBranch, |
|
|
@ -590,8 +618,12 @@ func GetPullRequestByIndex(repoID int64, index int64) (*PullRequest, error) { |
|
|
|
return nil, ErrPullRequestNotExist{0, repoID, index, 0, "", ""} |
|
|
|
return nil, ErrPullRequestNotExist{0, repoID, index, 0, "", ""} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pr.LoadAttributes() |
|
|
|
if err = pr.LoadAttributes(); err != nil { |
|
|
|
pr.LoadIssue() |
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if err = pr.LoadIssue(); err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return pr, nil |
|
|
|
return pr, nil |
|
|
|
} |
|
|
|
} |
|
|
|