@@ -225,21 +225,47 @@ func createPullRequest(ctx context.Context, client RESTClientInterface, repo git
225
225
"body" : body ,
226
226
}
227
227
228
+ requestBody , err := encodePayload (payload )
229
+ if err != nil {
230
+ return fmt .Errorf ("failed to encode payload: %w" , err )
231
+ }
232
+
233
+ // Create the pull request
234
+ var prResponse struct {
235
+ Number int `json:"number"`
236
+ }
237
+ err = client .Post (endpoint , requestBody , & prResponse )
238
+ if err != nil {
239
+ return fmt .Errorf ("failed to create pull request: %w" , err )
240
+ }
241
+
228
242
// Add labels if provided
229
243
if len (labels ) > 0 {
230
- payload ["labels" ] = labels
244
+ labelsEndpoint := fmt .Sprintf ("repos/%s/%s/issues/%d/labels" , repo .Owner , repo .Repo , prResponse .Number )
245
+ labelsPayload , err := encodePayload (map [string ][]string {"labels" : labels })
246
+ if err != nil {
247
+ return fmt .Errorf ("failed to encode labels payload: %w" , err )
248
+ }
249
+ err = client .Post (labelsEndpoint , labelsPayload , nil )
250
+ if err != nil {
251
+ return fmt .Errorf ("failed to add labels: %w" , err )
252
+ }
231
253
}
232
254
233
255
// Add assignees if provided
234
256
if len (assignees ) > 0 {
235
- payload ["assignees" ] = assignees
257
+ assigneesEndpoint := fmt .Sprintf ("repos/%s/%s/issues/%d/assignees" , repo .Owner , repo .Repo , prResponse .Number )
258
+ assigneesPayload , err := encodePayload (map [string ][]string {"assignees" : assignees })
259
+ if err != nil {
260
+ return fmt .Errorf ("failed to encode assignees payload: %w" , err )
261
+ }
262
+ err = client .Post (assigneesEndpoint , assigneesPayload , nil )
263
+ if err != nil {
264
+ return fmt .Errorf ("failed to add assignees: %w" , err )
265
+ }
236
266
}
237
267
238
- requestBody , err := encodePayload (payload )
239
- if err != nil {
240
- return fmt .Errorf ("failed to encode payload: %w" , err )
241
- }
242
- return client .Post (endpoint , requestBody , nil )
268
+ return nil
243
269
}
244
270
245
271
// encodePayload encodes a payload as JSON and returns an io.Reader
0 commit comments