Skip to content

Commit 8c58e93

Browse files
committed
Mods to support merge_method (#174).
1 parent 80cd605 commit 8c58e93

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

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

+4
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,7 @@ public Project createProject(Project project) throws GitLabApiException {
590590
* visibility (optional) - Limit by visibility public, internal, or private
591591
* visibilityLevel (optional)
592592
* issuesEnabled (optional) - Enable issues for this project
593+
* mergeMethod (optional) - Set the merge method used
593594
* mergeRequestsEnabled (optional) - Enable merge requests for this project
594595
* wikiEnabled (optional) - Enable wiki for this project
595596
* snippetsEnabled (optional) - Enable snippets for this project
@@ -629,6 +630,7 @@ public Project createProject(Project project, String importUrl) throws GitLabApi
629630
.withParam("default_branch", project.getDefaultBranch())
630631
.withParam("description", project.getDescription())
631632
.withParam("issues_enabled", project.getIssuesEnabled())
633+
.withParam("merge_method", project.getMergeMethod())
632634
.withParam("merge_requests_enabled", project.getMergeRequestsEnabled())
633635
.withParam("jobs_enabled", project.getJobsEnabled())
634636
.withParam("wiki_enabled", project.getWikiEnabled())
@@ -822,6 +824,7 @@ public Project createProject(String name, Integer namespaceId, String descriptio
822824
* description (optional) - short project description
823825
* visibility (optional) - Limit by visibility public, internal, or private
824826
* issuesEnabled (optional) - Enable issues for this project
827+
* mergeMethod (optional) - Set the merge method used
825828
* mergeRequestsEnabled (optional) - Enable merge requests for this project
826829
* wikiEnabled (optional) - Enable wiki for this project
827830
* snippetsEnabled (optional) - Enable snippets for this project
@@ -869,6 +872,7 @@ public Project updateProject(Project project) throws GitLabApiException {
869872
.withParam("default_branch", project.getDefaultBranch())
870873
.withParam("description", project.getDescription())
871874
.withParam("issues_enabled", project.getIssuesEnabled())
875+
.withParam("merge_method", project.getMergeMethod())
872876
.withParam("merge_requests_enabled", project.getMergeRequestsEnabled())
873877
.withParam("jobs_enabled", project.getJobsEnabled())
874878
.withParam("wiki_enabled", project.getWikiEnabled())

src/main/java/org/gitlab4j/api/models/Project.java

+42
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,38 @@
88
import javax.xml.bind.annotation.XmlAccessorType;
99
import javax.xml.bind.annotation.XmlRootElement;
1010

11+
import org.gitlab4j.api.utils.JacksonJsonEnumHelper;
12+
13+
import com.fasterxml.jackson.annotation.JsonCreator;
14+
import com.fasterxml.jackson.annotation.JsonValue;
15+
1116
@XmlRootElement
1217
@XmlAccessorType(XmlAccessType.FIELD)
1318
public class Project {
1419

20+
// Enum for the merge_method of the Project instance.
21+
public enum MergeMethod {
22+
23+
MERGE, REBASE_MERGE, FF;
24+
25+
private static JacksonJsonEnumHelper<MergeMethod> enumHelper = new JacksonJsonEnumHelper<>(MergeMethod.class);
26+
27+
@JsonCreator
28+
public static MergeMethod forValue(String value) {
29+
return enumHelper.forValue(value);
30+
}
31+
32+
@JsonValue
33+
public String toValue() {
34+
return (enumHelper.toString(this));
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return (enumHelper.toString(this));
40+
}
41+
}
42+
1543
private Integer approvalsBeforeMerge;
1644
private Boolean archived;
1745
private String avatarUrl;
@@ -29,6 +57,7 @@ public class Project {
2957
private Boolean jobsEnabled;
3058
private Date lastActivityAt;
3159
private Boolean lfsEnabled;
60+
private MergeMethod mergeMethod;
3261
private Boolean mergeRequestsEnabled;
3362
private String name;
3463
private Namespace namespace;
@@ -225,6 +254,19 @@ public Project withLfsEnabled(Boolean lfsEnabled) {
225254
return (this);
226255
}
227256

257+
public MergeMethod getMergeMethod() {
258+
return mergeMethod;
259+
}
260+
261+
public void setMergeMethod(MergeMethod mergeMethod) {
262+
this.mergeMethod = mergeMethod;
263+
}
264+
265+
public Project withMergeMethod(MergeMethod mergeMethod) {
266+
this.mergeMethod = mergeMethod;
267+
return (this);
268+
}
269+
228270
public Boolean getMergeRequestsEnabled() {
229271
return mergeRequestsEnabled;
230272
}

src/main/java/org/gitlab4j/api/utils/JacksonJsonEnumHelper.java

+11
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ public JacksonJsonEnumHelper(Class<E> enumType, boolean firstLetterCapitalized,
5858
}
5959
}
6060

61+
/**
62+
* Add an enum that has a specialized name that does not fit the standard naming conventions.
63+
*
64+
* @param e the enum to add
65+
* @param name the name for the enum
66+
*/
67+
public void addEnum(E e, String name) {
68+
valuesMap.put(name, e);
69+
namesMap.put(e, name);
70+
}
71+
6172
@JsonCreator
6273
public E forValue(String value) {
6374
return valuesMap.get(value);

src/test/resources/org/gitlab4j/api/project.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@
6666
"repository_storage": "default",
6767
"only_allow_merge_if_pipeline_succeeds": false,
6868
"only_allow_merge_if_all_discussions_are_resolved": false,
69-
"request_access_enabled": false
69+
"request_access_enabled": false,
70+
"merge_method": "merge"
7071
}

0 commit comments

Comments
 (0)