Skip to content

Commit 53845f3

Browse files
eutkingmessner
authored andcommitted
Additional method for create of Merge Request with squash parameter (#217)
1 parent 4b72785 commit 53845f3

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

src/main/java/org/gitlab4j/api/MergeRequestApi.java

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package org.gitlab4j.api;
22

3-
import java.util.List;
4-
import java.util.Optional;
5-
6-
import javax.ws.rs.core.Form;
7-
import javax.ws.rs.core.GenericType;
8-
import javax.ws.rs.core.MultivaluedMap;
9-
import javax.ws.rs.core.Response;
10-
113
import org.gitlab4j.api.GitLabApi.ApiVersion;
124
import org.gitlab4j.api.models.Commit;
135
import org.gitlab4j.api.models.MergeRequest;
146
import org.gitlab4j.api.models.MergeRequestFilter;
157
import org.gitlab4j.api.models.Participant;
168

9+
import javax.ws.rs.core.Form;
10+
import javax.ws.rs.core.GenericType;
11+
import javax.ws.rs.core.MultivaluedMap;
12+
import javax.ws.rs.core.Response;
13+
import java.util.List;
14+
import java.util.Optional;
15+
1716
/**
1817
* This class implements the client side API for the GitLab merge request calls.
1918
*/
@@ -269,11 +268,13 @@ public Pager<Commit> getCommits(int projectId, int mergeRequestIid, int itemsPer
269268
* @param labels labels for MR, optional
270269
* @param milestoneId the ID of a milestone, optional
271270
* @param removeSourceBranch Flag indicating if a merge request should remove the source branch when merging, optional
271+
* @param squash Squash commits into a single commit when merging, optional
272272
* @return the created MergeRequest instance
273273
* @throws GitLabApiException if any exception occurs
274+
* @since GitLab Starter 8.17, GitLab CE 11.0.
274275
*/
275276
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId,
276-
Integer targetProjectId, String[] labels, Integer milestoneId, Boolean removeSourceBranch)
277+
Integer targetProjectId, String[] labels, Integer milestoneId, Boolean removeSourceBranch, Boolean squash)
277278
throws GitLabApiException {
278279
if (projectId == null) {
279280
throw new RuntimeException("projectId cannot be null");
@@ -289,11 +290,37 @@ public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, S
289290
addFormParam(formData, "labels", labels == null ? null : String.join(",", labels), false);
290291
addFormParam(formData, "milestone_id", milestoneId, false);
291292
addFormParam(formData, "remove_source_branch", removeSourceBranch, false);
293+
addFormParam(formData, "squash", squash, false);
292294

293295
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "merge_requests");
294296
return (response.readEntity(MergeRequest.class));
295297
}
296298

299+
300+
/**
301+
* Creates a merge request and optionally assigns a reviewer to it.
302+
*
303+
* POST /projects/:id/merge_requests
304+
*
305+
* @param projectId the ID of a project, required
306+
* @param sourceBranch the source branch, required
307+
* @param targetBranch the target branch, required
308+
* @param title the title for the merge request, required
309+
* @param description the description of the merge request
310+
* @param assigneeId the Assignee user ID, optional
311+
* @param targetProjectId the ID of a target project, optional
312+
* @param labels labels for MR, optional
313+
* @param milestoneId the ID of a milestone, optional
314+
* @param removeSourceBranch Flag indicating if a merge request should remove the source branch when merging, optional
315+
* @return the created MergeRequest instance
316+
* @throws GitLabApiException if any exception occurs
317+
*/
318+
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId,
319+
Integer targetProjectId, String[] labels, Integer milestoneId, Boolean removeSourceBranch)
320+
throws GitLabApiException {
321+
return createMergeRequest(projectId, sourceBranch, targetBranch, title, description, assigneeId, targetProjectId, labels, milestoneId, removeSourceBranch, null);
322+
}
323+
297324
/**
298325
* Creates a merge request and optionally assigns a reviewer to it.
299326
*
@@ -511,7 +538,7 @@ public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIi
511538
* @return the merged merge request
512539
* @throws GitLabApiException if any exception occurs
513540
*/
514-
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIid,
541+
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIid,
515542
String mergeCommitMessage, Boolean shouldRemoveSourceBranch, Boolean mergeWhenPipelineSucceeds)
516543
throws GitLabApiException {
517544
return (acceptMergeRequest(projectId, mergeRequestIid, mergeCommitMessage,
@@ -540,7 +567,7 @@ public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIi
540567
* @return the merged merge request
541568
* @throws GitLabApiException if any exception occurs
542569
*/
543-
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIid,
570+
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIid,
544571
String mergeCommitMessage, Boolean shouldRemoveSourceBranch, Boolean mergeWhenPipelineSucceeds, String sha)
545572
throws GitLabApiException {
546573

0 commit comments

Comments
 (0)