@@ -3,23 +3,26 @@ package bitbucket
33import (
44 "encoding/json"
55 "net/url"
6- "os"
7-
8- "github.com/k0kubun/pp"
96)
107
118type PullRequests struct {
129 c * Client
1310}
1411
1512func (p * PullRequests ) Create (po * PullRequestsOptions ) (interface {}, error ) {
16- data := p .buildPullRequestBody (po )
13+ data , err := p .buildPullRequestBody (po )
14+ if err != nil {
15+ return nil , err
16+ }
1717 urlStr := p .c .requestUrl ("/repositories/%s/%s/pullrequests/" , po .Owner , po .RepoSlug )
1818 return p .c .execute ("POST" , urlStr , data )
1919}
2020
2121func (p * PullRequests ) Update (po * PullRequestsOptions ) (interface {}, error ) {
22- data := p .buildPullRequestBody (po )
22+ data , err := p .buildPullRequestBody (po )
23+ if err != nil {
24+ return nil , err
25+ }
2326 urlStr := p .c .GetApiBaseURL () + "/repositories/" + po .Owner + "/" + po .RepoSlug + "/pullrequests/" + po .ID
2427 return p .c .execute ("PUT" , urlStr , data )
2528}
@@ -96,13 +99,19 @@ func (p *PullRequests) Diff(po *PullRequestsOptions) (interface{}, error) {
9699}
97100
98101func (p * PullRequests ) Merge (po * PullRequestsOptions ) (interface {}, error ) {
99- data := p .buildPullRequestBody (po )
102+ data , err := p .buildPullRequestBody (po )
103+ if err != nil {
104+ return nil , err
105+ }
100106 urlStr := p .c .GetApiBaseURL () + "/repositories/" + po .Owner + "/" + po .RepoSlug + "/pullrequests/" + po .ID + "/merge"
101107 return p .c .execute ("POST" , urlStr , data )
102108}
103109
104110func (p * PullRequests ) Decline (po * PullRequestsOptions ) (interface {}, error ) {
105- data := p .buildPullRequestBody (po )
111+ data , err := p .buildPullRequestBody (po )
112+ if err != nil {
113+ return nil , err
114+ }
106115 urlStr := p .c .GetApiBaseURL () + "/repositories/" + po .Owner + "/" + po .RepoSlug + "/pullrequests/" + po .ID + "/decline"
107116 return p .c .execute ("POST" , urlStr , data )
108117}
@@ -173,8 +182,7 @@ func (p *PullRequests) Statuses(po *PullRequestsOptions) (interface{}, error) {
173182 return p .c .execute ("GET" , urlStr , "" )
174183}
175184
176- func (p * PullRequests ) buildPullRequestBody (po * PullRequestsOptions ) string {
177-
185+ func (p * PullRequests ) buildPullRequestBody (po * PullRequestsOptions ) (string , error ) {
178186 body := map [string ]interface {}{}
179187 body ["source" ] = map [string ]interface {}{}
180188 body ["destination" ] = map [string ]interface {}{}
@@ -225,11 +233,10 @@ func (p *PullRequests) buildPullRequestBody(po *PullRequestsOptions) string {
225233
226234 data , err := json .Marshal (body )
227235 if err != nil {
228- pp .Println (err )
229- os .Exit (9 )
236+ return "" , err
230237 }
231238
232- return string (data )
239+ return string (data ), nil
233240}
234241
235242func (p * PullRequests ) buildPullRequestCommentBody (co * PullRequestCommentOptions ) (string , error ) {
0 commit comments