@@ -329,21 +329,61 @@ public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, S
329
329
* @param stateEvent new state for the merge request, optional
330
330
* @param labels comma separated list of labels, optional
331
331
* @param milestoneId the ID of a milestone, optional
332
+ * @param removeSourceBranch Flag indicating if a merge request should remove the source
333
+ * branch when merging, optional
334
+ * @param squash Squash commits into a single commit when merging, optional
335
+ * @param discussionLocked Flag indicating if the merge request's discussion is locked, optional
336
+ * @param allowCollaboration Allow commits from members who can merge to the target branch,
337
+ * optional
332
338
* @return the updated merge request
333
339
* @throws GitLabApiException if any exception occurs
334
340
*/
341
+ public MergeRequest updateMergeRequest (Integer projectId , Integer mergeRequestIid ,
342
+ String targetBranch , String title , Integer assigneeId , String description ,
343
+ StateEvent stateEvent , String labels , Integer milestoneId , Boolean removeSourceBranch ,
344
+ Boolean squash , Boolean discussionLocked , Boolean allowCollaboration )
345
+ throws GitLabApiException {
346
+
347
+ Form formData = new GitLabApiForm ()
348
+ .withParam ("target_branch" , targetBranch )
349
+ .withParam ("title" , title )
350
+ .withParam ("assignee_id" , assigneeId )
351
+ .withParam ("description" , description )
352
+ .withParam ("state_event" , stateEvent )
353
+ .withParam ("labels" , labels )
354
+ .withParam ("milestone_id" , milestoneId )
355
+ .withParam ("remove_source_branch" , removeSourceBranch )
356
+ .withParam ("squash" , squash )
357
+ .withParam ("discussion_locked" , discussionLocked )
358
+ .withParam ("allow_collaboration" , allowCollaboration );
359
+
360
+ return updateMergeRequest (projectId , mergeRequestIid , formData );
361
+ }
362
+
363
+ /**
364
+ * Updates an existing merge request. You can change branches, title, or even close the MR.
365
+ *
366
+ * <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
367
+ *
368
+ * PUT /projects/:id/merge_requests/:merge_request_iid
369
+ *
370
+ * @param projectId the ID of a project
371
+ * @param mergeRequestIid the internal ID of the merge request to update
372
+ * @param targetBranch the target branch, optional
373
+ * @param title the title for the merge request
374
+ * @param assigneeId the Assignee user ID, optional
375
+ * @param description the description of the merge request, optional
376
+ * @param stateEvent new state for the merge request, optional
377
+ * @param labels comma separated list of labels, optional
378
+ * @param milestoneId the ID of a milestone, optional
379
+ * @return the updated merge request
380
+ * @throws GitLabApiException if any exception occurs
381
+ */
382
+ @ Deprecated
335
383
public MergeRequest updateMergeRequest (Integer projectId , Integer mergeRequestIid , String targetBranch ,
336
384
String title , Integer assigneeId , String description , StateEvent stateEvent , String labels ,
337
385
Integer milestoneId ) throws GitLabApiException {
338
386
339
- if (projectId == null ) {
340
- throw new RuntimeException ("projectId cannot be null" );
341
- }
342
-
343
- if (mergeRequestIid == null ) {
344
- throw new RuntimeException ("mergeRequestIid cannot be null" );
345
- }
346
-
347
387
Form formData = new GitLabApiForm ()
348
388
.withParam ("target_branch" , targetBranch )
349
389
.withParam ("title" , title )
@@ -353,8 +393,7 @@ public MergeRequest updateMergeRequest(Integer projectId, Integer mergeRequestIi
353
393
.withParam ("labels" , labels )
354
394
.withParam ("milestone_id" , milestoneId );
355
395
356
- Response response = put (Response .Status .OK , formData .asMap (), "projects" , projectId , "merge_requests" , mergeRequestIid );
357
- return (response .readEntity (MergeRequest .class ));
396
+ return updateMergeRequest (projectId , mergeRequestIid , formData );
358
397
}
359
398
360
399
/**
@@ -379,6 +418,19 @@ public MergeRequest updateMergeRequest(Integer projectId, Integer mergeRequestIi
379
418
public MergeRequest updateMergeRequest (Integer projectId , Integer mergeRequestIid , String sourceBranch , String targetBranch , String title , String description ,
380
419
Integer assigneeId ) throws GitLabApiException {
381
420
421
+ Form formData = new Form ();
422
+ addFormParam (formData , "source_branch" , sourceBranch , false );
423
+ addFormParam (formData , "target_branch" , targetBranch , false );
424
+ addFormParam (formData , "title" , title , false );
425
+ addFormParam (formData , "description" , description , false );
426
+ addFormParam (formData , "assignee_id" , assigneeId , false );
427
+
428
+ return updateMergeRequest (projectId , mergeRequestIid , formData );
429
+ }
430
+
431
+ protected MergeRequest updateMergeRequest (Integer projectId , Integer mergeRequestIid ,
432
+ Form formData ) throws GitLabApiException {
433
+
382
434
if (projectId == null ) {
383
435
throw new RuntimeException ("projectId cannot be null" );
384
436
}
@@ -387,14 +439,8 @@ public MergeRequest updateMergeRequest(Integer projectId, Integer mergeRequestIi
387
439
throw new RuntimeException ("mergeRequestId cannot be null" );
388
440
}
389
441
390
- Form formData = new Form ();
391
- addFormParam (formData , "source_branch" , sourceBranch , false );
392
- addFormParam (formData , "target_branch" , targetBranch , false );
393
- addFormParam (formData , "title" , title , false );
394
- addFormParam (formData , "description" , description , false );
395
- addFormParam (formData , "assignee_id" , assigneeId , false );
396
-
397
- Response response = put (Response .Status .OK , formData .asMap (), "projects" , projectId , "merge_requests" , mergeRequestIid );
442
+ Response response = put (Response .Status .OK , formData .asMap (), "projects" , projectId ,
443
+ "merge_requests" , mergeRequestIid );
398
444
return (response .readEntity (MergeRequest .class ));
399
445
}
400
446
0 commit comments