Skip to content

Commit 77cb707

Browse files
committed
Fixed issue with target_type when fetching user events (#190).
1 parent 8158bca commit 77cb707

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targ
5555

5656
GitLabApiForm formData = new GitLabApiForm()
5757
.withParam("action", action)
58-
.withParam("target_type", targetType)
58+
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
5959
.withParam("before", before)
6060
.withParam("after", after)
6161
.withParam("sort", sortOrder)
@@ -85,7 +85,7 @@ public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType tar
8585

8686
GitLabApiForm formData = new GitLabApiForm()
8787
.withParam("action", action)
88-
.withParam("target_type", targetType)
88+
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
8989
.withParam("before", before)
9090
.withParam("after", after)
9191
.withParam("sort", sortOrder);
@@ -137,7 +137,7 @@ public List<Event> getUserEvents(Integer userId, ActionType action, TargetType t
137137

138138
GitLabApiForm formData = new GitLabApiForm()
139139
.withParam("action", action)
140-
.withParam("target_type", targetType)
140+
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
141141
.withParam("before", before)
142142
.withParam("after", after)
143143
.withParam("sort", sortOrder)
@@ -172,7 +172,7 @@ public Pager<Event> getUserEvents(Integer userId, ActionType action, TargetType
172172

173173
GitLabApiForm formData = new GitLabApiForm()
174174
.withParam("action", action)
175-
.withParam("target_type", targetType)
175+
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
176176
.withParam("before", before)
177177
.withParam("after", after)
178178
.withParam("sort", sortOrder);
@@ -224,7 +224,7 @@ public List<Event> getProjectEvents(Integer projectId, ActionType action, Target
224224

225225
GitLabApiForm formData = new GitLabApiForm()
226226
.withParam("action", action)
227-
.withParam("target_type", targetType)
227+
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
228228
.withParam("before", before)
229229
.withParam("after", after)
230230
.withParam("sort", sortOrder)
@@ -259,7 +259,7 @@ public Pager<Event> getProjectEvents(Integer projectId, ActionType action, Targe
259259

260260
GitLabApiForm formData = new GitLabApiForm()
261261
.withParam("action", action)
262-
.withParam("target_type", targetType)
262+
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
263263
.withParam("before", before)
264264
.withParam("after", after)
265265
.withParam("sort", sortOrder);

src/test/java/org/gitlab4j/api/TestEventsApi.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ public void testGetUserEvents() throws GitLabApiException {
118118
List<Event> events = gitLabApi.getEventsApi().getUserEvents(testUser.getId(), null, null, null, null, null);
119119
assertNotNull(events);
120120
}
121-
122-
public void testGetUserEvents1() throws GitLabApiException, ParseException {
121+
122+
@Test
123+
public void testGetUserEventsWithAllParams() throws GitLabApiException, ParseException {
123124
assertNotNull(testUser);
124-
125-
Date before = ISO8601.toDate("2018-06-02");
126-
Date after = ISO8601.toDate("2018-05-01");
125+
Date before = ISO8601.toDate("2017-06-02");
126+
Date after = new Date();
127127
List<Event> events = gitLabApi.getEventsApi().getUserEvents(testUser.getId(), Constants.ActionType.CREATED, Constants.TargetType.PROJECT, before, after, Constants.SortOrder.DESC);
128128
assertNotNull(events);
129129
}
@@ -141,13 +141,12 @@ public void testPagedGetAuthenticatedUserEvents() throws GitLabApiException {
141141
assertNotNull(events);
142142
}
143143

144-
// This is commented out because it was causing a "Too Many Requests" error from gitlab.com, thus causing the tests to fail
145-
// @Test
146-
// public void testPagedGetUserEvents() throws GitLabApiException {
147-
// assertNotNull(testUser);
148-
// Pager<Event> events = gitLabApi.getEventsApi().getUserEvents(testUser.getId(), null, null, null, null, null, 10);
149-
// assertNotNull(events);
150-
// }
144+
@Test
145+
public void testPagedGetUserEvents() throws GitLabApiException {
146+
assertNotNull(testUser);
147+
Pager<Event> events = gitLabApi.getEventsApi().getUserEvents(testUser.getId(), null, null, null, null, null, 10);
148+
assertNotNull(events);
149+
}
151150

152151
@Test
153152
public void testPagedGetProjectEvents() throws GitLabApiException {

0 commit comments

Comments
 (0)