Skip to content

Commit 13afdbb

Browse files
committed
Mods to support EventsApi (#60).
1 parent c50c87c commit 13afdbb

File tree

4 files changed

+114
-18
lines changed

4 files changed

+114
-18
lines changed

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

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ public static SortOrder forValue(String value) {
4545

4646
@JsonValue
4747
public String toValue() {
48-
return (name().toLowerCase());
48+
return (enumHelper.toString(this));
4949
}
5050

5151
@Override
5252
public String toString() {
53-
return (name().toLowerCase());
53+
return (enumHelper.toString(this));
5454
}
5555
}
5656

@@ -67,12 +67,12 @@ public static ProjectOrderBy forValue(String value) {
6767

6868
@JsonValue
6969
public String toValue() {
70-
return (name().toLowerCase());
70+
return (enumHelper.toString(this));
7171
}
7272

7373
@Override
7474
public String toString() {
75-
return (name().toLowerCase());
75+
return (enumHelper.toString(this));
7676
}
7777
}
7878

@@ -90,12 +90,12 @@ public static PipelineOrderBy forValue(String value) {
9090

9191
@JsonValue
9292
public String toValue() {
93-
return (name().toLowerCase());
93+
return (enumHelper.toString(this));
9494
}
9595

9696
@Override
9797
public String toString() {
98-
return (name().toLowerCase());
98+
return (enumHelper.toString(this));
9999
}
100100
}
101101

@@ -113,12 +113,12 @@ public static PipelineScope forValue(String value) {
113113

114114
@JsonValue
115115
public String toValue() {
116-
return (name().toLowerCase());
116+
return (enumHelper.toString(this));
117117
}
118118

119119
@Override
120120
public String toString() {
121-
return (name().toLowerCase());
121+
return (enumHelper.toString(this));
122122
}
123123
}
124124

@@ -133,10 +133,14 @@ public enum JobScope {
133133
public static JobScope forValue(String value) { return enumHelper.forValue(value); }
134134

135135
@JsonValue
136-
public String toValue() { return (name().toLowerCase()); }
136+
public String toValue() {
137+
return (enumHelper.toString(this));
138+
}
137139

138140
@Override
139-
public String toString() { return (name().toLowerCase()); }
141+
public String toString() {
142+
return (enumHelper.toString(this));
143+
}
140144
}
141145

142146
/** Enum to use for specifying the state of a merge request update. */
@@ -149,10 +153,61 @@ public enum StateEvent {
149153
@JsonCreator
150154
public static StateEvent forValue(String value) { return enumHelper.forValue(value); }
151155

156+
152157
@JsonValue
153-
public String toValue() { return (name().toLowerCase()); }
158+
public String toValue() {
159+
return (enumHelper.toString(this));
160+
}
154161

155162
@Override
156-
public String toString() { return (name().toLowerCase()); }
163+
public String toString() {
164+
return (enumHelper.toString(this));
165+
}
166+
}
167+
168+
/** Enum to use for specifying the event action_type. */
169+
public enum ActionType {
170+
171+
CREATED, UPDATED, CLOSED, REOPENED, PUSHED, COMMENTED, MERGED, JOINED, LEFT, DESTROYED, EXPIRED;
172+
173+
private static JacksonJsonEnumHelper<ActionType> enumHelper = new JacksonJsonEnumHelper<>(ActionType.class);
174+
175+
@JsonCreator
176+
public static ActionType forValue(String value) {
177+
return enumHelper.forValue(value);
178+
}
179+
180+
@JsonValue
181+
public String toValue() {
182+
return (enumHelper.toString(this));
183+
}
184+
185+
@Override
186+
public String toString() {
187+
return (enumHelper.toString(this));
188+
}
189+
}
190+
191+
/** Enum to use for specifying the event target_type. */
192+
public enum TargetType {
193+
194+
ISSUE, MILESTONE, MERGE_REQUEST, NOTE, PROJECT, SNIPPET, USER;
195+
196+
private static JacksonJsonEnumHelper<TargetType> enumHelper = new JacksonJsonEnumHelper<>(TargetType.class, true);
197+
198+
@JsonCreator
199+
public static TargetType forValue(String value) {
200+
return enumHelper.forValue(value);
201+
}
202+
203+
@JsonValue
204+
public String toValue() {
205+
return (enumHelper.toString(this));
206+
}
207+
208+
@Override
209+
public String toString() {
210+
return (enumHelper.toString(this));
211+
}
157212
}
158213
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public String getApiNamespace() {
4141
private UserApi userApi;
4242
private JobApi jobApi;
4343
private NotesApi notesApi;
44+
private EventsApi eventsApi;
4445

4546
private Session session;
4647

@@ -192,6 +193,7 @@ public GitLabApi(ApiVersion apiVersion, String hostUrl, String privateToken, Str
192193
repositoryFileApi = new RepositoryFileApi(this);
193194
jobApi = new JobApi(this);
194195
notesApi = new NotesApi(this);
196+
eventsApi = new EventsApi(this);
195197
}
196198

197199
/**
@@ -401,7 +403,9 @@ public UserApi getUserApi() {
401403
*
402404
* @return the JobsApi instance owned by this GitLabApi instance
403405
*/
404-
public JobApi getJobApi() { return (jobApi); }
406+
public JobApi getJobApi() {
407+
return (jobApi);
408+
}
405409

406410
/**
407411
* Gets the NotesApi instance owned by this GitLabApi instance. The NotesApi is used
@@ -413,4 +417,13 @@ public NotesApi getNotesApi() {
413417
return (notesApi);
414418
}
415419

420+
/**
421+
* Gets the EventsApi instance owned by this GitLabApi instance. The EventsApi is used
422+
* to perform all events related API calls.
423+
*
424+
* @return the EventsApi instance owned by this GitLabApi instance
425+
*/
426+
public EventsApi getEventsApi() {
427+
return (eventsApi);
428+
}
416429
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import javax.xml.bind.annotation.XmlAccessorType;
66
import javax.xml.bind.annotation.XmlRootElement;
77

8+
import org.gitlab4j.api.Constants.TargetType;
9+
810
@XmlRootElement
911
@XmlAccessorType(XmlAccessType.FIELD)
1012
public class Event {
@@ -17,7 +19,7 @@ public class Event {
1719
private Integer projectId;
1820
private Integer targetId;
1921
private String targetTitle;
20-
private String targetType;
22+
private TargetType targetType;
2123
private String title;
2224

2325
public String getActionName() {
@@ -84,11 +86,11 @@ public void setTargetTitle(String targetTitle) {
8486
this.targetTitle = targetTitle;
8587
}
8688

87-
public String getTargetType() {
89+
public TargetType getTargetType() {
8890
return targetType;
8991
}
9092

91-
public void setTargetType(String targetType) {
93+
public void setTargetType(TargetType targetType) {
9294
this.targetType = targetType;
9395
}
9496

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,41 @@
88
public class JacksonJsonEnumHelper<E extends Enum<E>> {
99

1010
private Map<String, E> valuesMap;
11+
private Map<E, String> namesMap;
1112

1213
public JacksonJsonEnumHelper(Class<E> enumType) {
14+
this(enumType, false);
15+
}
16+
17+
public JacksonJsonEnumHelper(Class<E> enumType, boolean firstLetterCapitalized) {
18+
1319
valuesMap = new HashMap<>();
14-
for (E e : enumType.getEnumConstants())
15-
valuesMap.put(e.name().toLowerCase(), e);
20+
namesMap = new HashMap<>();
21+
22+
for (E e : enumType.getEnumConstants()) {
23+
24+
String name = e.name().toLowerCase();
25+
if (firstLetterCapitalized) {
26+
name = name.substring(0, 1).toUpperCase() + name.substring(1);
27+
}
28+
29+
valuesMap.put(name, e);
30+
namesMap.put(e, name);
31+
}
1632
}
1733

1834
@JsonCreator
1935
public E forValue(String value) {
2036
return valuesMap.get(value);
2137
}
38+
39+
/**
40+
* Get the string used by the API for this enum.
41+
*
42+
* @param e the enum value to get the API string for
43+
* @return the string used by the API for this enum
44+
*/
45+
public String toString(E e) {
46+
return (namesMap.get(e));
47+
}
2248
}

0 commit comments

Comments
 (0)