@@ -121,12 +121,40 @@ func (pr *PullRequest) LoadIssue() (err error) {
121
121
// Required - Issue
122
122
// Optional - Merger
123
123
func (pr * PullRequest ) APIFormat () * api.PullRequest {
124
-
124
+ var (
125
+ baseBranch * Branch
126
+ headBranch * Branch
127
+ baseCommit * git.Commit
128
+ headCommit * git.Commit
129
+ err error
130
+ )
125
131
apiIssue := pr .Issue .APIFormat ()
126
- baseBranch , _ := pr .BaseRepo .GetBranch (pr .BaseBranch )
127
- baseCommit , _ := baseBranch .GetCommit ()
128
- headBranch , _ := pr .HeadRepo .GetBranch (pr .HeadBranch )
129
- headCommit , _ := headBranch .GetCommit ()
132
+ if pr .BaseRepo == nil {
133
+ pr .BaseRepo , err = GetRepositoryByID (pr .BaseRepoID )
134
+ if err != nil {
135
+ log .Error (log .ERROR , "GetRepositoryById[%d]: %v" , pr .ID , err )
136
+ return nil
137
+ }
138
+ }
139
+ if pr .HeadRepo == nil {
140
+ pr .HeadRepo , err = GetRepositoryByID (pr .HeadRepoID )
141
+ if err != nil {
142
+ log .Error (log .ERROR , "GetRepositoryById[%d]: %v" , pr .ID , err )
143
+ return nil
144
+ }
145
+ }
146
+ if baseBranch , err = pr .BaseRepo .GetBranch (pr .BaseBranch ); err != nil {
147
+ return nil
148
+ }
149
+ if baseCommit , err = baseBranch .GetCommit (); err != nil {
150
+ return nil
151
+ }
152
+ if headBranch , err = pr .HeadRepo .GetBranch (pr .HeadBranch ); err != nil {
153
+ return nil
154
+ }
155
+ if headCommit , err = headBranch .GetCommit (); err != nil {
156
+ return nil
157
+ }
130
158
apiBaseBranchInfo := & api.PRBranchInfo {
131
159
Name : pr .BaseBranch ,
132
160
Ref : pr .BaseBranch ,
@@ -590,8 +618,12 @@ func GetPullRequestByIndex(repoID int64, index int64) (*PullRequest, error) {
590
618
return nil , ErrPullRequestNotExist {0 , repoID , index , 0 , "" , "" }
591
619
}
592
620
593
- pr .LoadAttributes ()
594
- pr .LoadIssue ()
621
+ if err = pr .LoadAttributes (); err != nil {
622
+ return nil , err
623
+ }
624
+ if err = pr .LoadIssue (); err != nil {
625
+ return nil , err
626
+ }
595
627
596
628
return pr , nil
597
629
}
0 commit comments