@@ -19,7 +19,7 @@ type pullService struct {
19
19
func (s * pullService ) Find (ctx context.Context , repo string , number int ) (* scm.PullRequest , * scm.Response , error ) {
20
20
namespace , name := scm .Split (repo )
21
21
path := fmt .Sprintf ("rest/api/1.0/projects/%s/repos/%s/pull-requests/%d" , namespace , name , number )
22
- out := new (pullRequest )
22
+ out := new (pr )
23
23
res , err := s .client .do (ctx , "GET" , path , nil , out )
24
24
return convertPullRequest (out ), res , err
25
25
}
@@ -35,7 +35,7 @@ func (s *pullService) FindComment(ctx context.Context, repo string, number int,
35
35
func (s * pullService ) List (ctx context.Context , repo string , opts scm.PullRequestListOptions ) ([]* scm.PullRequest , * scm.Response , error ) {
36
36
namespace , name := scm .Split (repo )
37
37
path := fmt .Sprintf ("rest/api/1.0/projects/%s/repos/%s/pull-requests" , namespace , name )
38
- out := new (pullRequests )
38
+ out := new (prs )
39
39
res , err := s .client .do (ctx , "GET" , path , nil , out )
40
40
if ! out .pagination .LastPage .Bool {
41
41
res .Page .First = 1
@@ -79,6 +79,23 @@ func (s *pullService) Close(ctx context.Context, repo string, number int) (*scm.
79
79
return res , err
80
80
}
81
81
82
+ func (s * pullService ) Create (ctx context.Context , repo string , input * scm.PullRequestInput ) (* scm.PullRequest , * scm.Response , error ) {
83
+ namespace , name := scm .Split (repo )
84
+ path := fmt .Sprintf ("rest/api/1.0/projects/%s/repos/%s/pull-requests" , namespace , name )
85
+ in := new (prInput )
86
+ in .Title = input .Title
87
+ in .Description = input .Body
88
+ in .FromRef .Repository .Project .Key = namespace
89
+ in .FromRef .Repository .Slug = name
90
+ in .FromRef .ID = scm .ExpandRef (input .Source , "refs/heads" )
91
+ in .ToRef .Repository .Project .Key = namespace
92
+ in .ToRef .Repository .Slug = name
93
+ in .ToRef .ID = scm .ExpandRef (input .Target , "refs/heads" )
94
+ out := new (pr )
95
+ res , err := s .client .do (ctx , "POST" , path , in , out )
96
+ return convertPullRequest (out ), res , err
97
+ }
98
+
82
99
func (s * pullService ) CreateComment (ctx context.Context , repo string , number int , in * scm.CommentInput ) (* scm.Comment , * scm.Response , error ) {
83
100
input := pullRequestCommentInput {Text : in .Body }
84
101
namespace , name := scm .Split (repo )
@@ -97,7 +114,7 @@ func (s *pullService) DeleteComment(context.Context, string, int, int) (*scm.Res
97
114
return nil , scm .ErrNotSupported
98
115
}
99
116
100
- type pullRequest struct {
117
+ type pr struct {
101
118
ID int `json:"id"`
102
119
Version int `json:"version"`
103
120
Title string `json:"title"`
@@ -146,20 +163,43 @@ type pullRequest struct {
146
163
} `json:"links"`
147
164
}
148
165
149
- type pullRequests struct {
166
+ type prs struct {
150
167
pagination
151
- Values []* pullRequest `json:"values"`
168
+ Values []* pr `json:"values"`
169
+ }
170
+
171
+ type prInput struct {
172
+ Title string `json:"title"`
173
+ Description string `json:"description"`
174
+ FromRef struct {
175
+ ID string `json:"id"`
176
+ Repository struct {
177
+ Slug string `json:"slug"`
178
+ Project struct {
179
+ Key string `json:"key"`
180
+ } `json:"project"`
181
+ } `json:"repository"`
182
+ } `json:"fromRef"`
183
+ ToRef struct {
184
+ ID string `json:"id"`
185
+ Repository struct {
186
+ Slug string `json:"slug"`
187
+ Project struct {
188
+ Key string `json:"key"`
189
+ } `json:"project"`
190
+ } `json:"repository"`
191
+ } `json:"toRef"`
152
192
}
153
193
154
- func convertPullRequests (from * pullRequests ) []* scm.PullRequest {
194
+ func convertPullRequests (from * prs ) []* scm.PullRequest {
155
195
to := []* scm.PullRequest {}
156
196
for _ , v := range from .Values {
157
197
to = append (to , convertPullRequest (v ))
158
198
}
159
199
return to
160
200
}
161
201
162
- func convertPullRequest (from * pullRequest ) * scm.PullRequest {
202
+ func convertPullRequest (from * pr ) * scm.PullRequest {
163
203
fork := scm .Join (
164
204
from .FromRef .Repository .Project .Key ,
165
205
from .FromRef .Repository .Slug ,
0 commit comments