Skip to content

Commit 0947d1f

Browse files
authored
Merge pull request #760 from beekeep/beekeep-patch-event-scope
Added support for scope attribute to EventsApi
2 parents c0d17ed + 5588ad8 commit 0947d1f

File tree

3 files changed

+135
-4
lines changed

3 files changed

+135
-4
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ public String toString() {
509509
/** Enum to use for specifying the event action_type. */
510510
public enum ActionType {
511511

512-
CREATED, UPDATED, CLOSED, REOPENED, PUSHED, COMMENTED, MERGED, JOINED, LEFT, DESTROYED, EXPIRED, REMOVED;
512+
CREATED, UPDATED, OPENED, CLOSED, REOPENED, PUSHED, COMMENTED, MERGED, JOINED, LEFT, DESTROYED, EXPIRED, REMOVED, DELETED, APPROVED, ACCEPTED, IMPORTED;
513513

514514
private static JacksonJsonEnumHelper<ActionType> enumHelper = new JacksonJsonEnumHelper<>(ActionType.class);
515515

@@ -962,5 +962,27 @@ public String toString() {
962962
return (enumHelper.toString(this));
963963
}
964964
}
965+
966+
/** Enum to use for specifying the Event scope. */
967+
public enum EventScope {
968+
ALL;
969+
970+
private static JacksonJsonEnumHelper<EventScope> enumHelper = new JacksonJsonEnumHelper<>(EventScope.class);
971+
972+
@JsonCreator
973+
public static EventScope forValue(String value) {
974+
return enumHelper.forValue(value);
975+
}
976+
977+
@JsonValue
978+
public String toValue() {
979+
return (enumHelper.toString(this));
980+
}
981+
982+
@Override
983+
public String toString() {
984+
return (enumHelper.toString(this));
985+
}
986+
}
965987
}
966988

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

Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targ
3636
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage()).all());
3737
}
3838

39+
/**
40+
* Get a list of all events for the authenticated user, across all of the user's projects.
41+
*
42+
* <pre><code>GitLab Endpoint: GET /events</code></pre>
43+
*
44+
* @param action include only events of a particular action type, optional
45+
* @param targetType include only events of a particular target type, optional
46+
* @param before include only events created before a particular date, optional
47+
* @param after include only events created after a particular date, optional
48+
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
49+
* @return a list of events for the authenticated user and matching the supplied parameters
50+
* @throws GitLabApiException if any exception occurs
51+
*/
52+
public List<Event> getAllAuthenticatedUserEvents(ActionType action, TargetType targetType,
53+
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
54+
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage(), EventScope.ALL).all());
55+
}
56+
3957
/**
4058
* Get a list of events for the authenticated user and in the specified page range.
4159
*
@@ -53,6 +71,27 @@ public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targ
5371
*/
5472
public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType,
5573
Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException {
74+
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, page, perPage, null));
75+
}
76+
77+
/**
78+
* Get a list of events for the authenticated user and in the specified page range.
79+
*
80+
* <pre><code>GitLab Endpoint: GET /events</code></pre>
81+
*
82+
* @param action include only events of a particular action type, optional
83+
* @param targetType include only events of a particular target type, optional
84+
* @param before include only events created before a particular date, optional
85+
* @param after include only events created after a particular date, optional
86+
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
87+
* @param page the page to get
88+
* @param perPage the number of projects per page
89+
* @param scope include all events across a user’s projects, optional
90+
* @return a list of events for the authenticated user and matching the supplied parameters
91+
* @throws GitLabApiException if any exception occurs
92+
*/
93+
public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType,
94+
Date before, Date after, SortOrder sortOrder, int page, int perPage, EventScope scope) throws GitLabApiException {
5695

5796
GitLabApiForm formData = new GitLabApiForm()
5897
.withParam("action", action)
@@ -61,7 +100,8 @@ public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targ
61100
.withParam("after", after)
62101
.withParam("sort", sortOrder)
63102
.withParam(PAGE_PARAM, page)
64-
.withParam(PER_PAGE_PARAM, perPage);
103+
.withParam(PER_PAGE_PARAM, perPage)
104+
.withParam("scope", scope != null ? scope.toValue().toLowerCase() : null);
65105

66106
Response response = get(Response.Status.OK, formData.asMap(), "events");
67107
return (response.readEntity(new GenericType<List<Event>>() {}));
@@ -83,13 +123,34 @@ public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targ
83123
*/
84124
public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after,
85125
SortOrder sortOrder, int itemsPerPage) throws GitLabApiException {
126+
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, itemsPerPage, null));
127+
}
128+
129+
/**
130+
* Get a list of events for the authenticated user and in the specified page range.
131+
*
132+
* <pre><code>GitLab Endpoint: GET /events</code></pre>
133+
*
134+
* @param action include only events of a particular action type, optional
135+
* @param targetType include only events of a particular target type, optional
136+
* @param before include only events created before a particular date, optional
137+
* @param after include only events created after a particular date, optional
138+
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
139+
* @param itemsPerPage the number of Event instances that will be fetched per page
140+
* @param scope include all events across a user’s projects, optional
141+
* @return a Pager of events for the authenticated user and matching the supplied parameters
142+
* @throws GitLabApiException if any exception occurs
143+
*/
144+
public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after,
145+
SortOrder sortOrder, int itemsPerPage, EventScope scope) throws GitLabApiException {
86146

87147
GitLabApiForm formData = new GitLabApiForm()
88148
.withParam("action", action)
89149
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
90150
.withParam("before", before)
91151
.withParam("after", after)
92-
.withParam("sort", sortOrder);
152+
.withParam("sort", sortOrder)
153+
.withParam("scope", scope != null ? scope.toValue().toLowerCase() : null);
93154

94155
return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "events"));
95156
}
@@ -109,7 +170,25 @@ public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType tar
109170
*/
110171
public Stream<Event> getAuthenticatedUserEventsStream(ActionType action, TargetType targetType,
111172
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
112-
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage()).stream());
173+
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage(), null).stream());
174+
}
175+
176+
/**
177+
* Get a Stream of all events for the authenticated user, across all of the user's projects.
178+
*
179+
* <pre><code>GitLab Endpoint: GET /events</code></pre>
180+
*
181+
* @param action include only events of a particular action type, optional
182+
* @param targetType include only events of a particular target type, optional
183+
* @param before include only events created before a particular date, optional
184+
* @param after include only events created after a particular date, optional
185+
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
186+
* @return a Stream of events for the authenticated user and matching the supplied parameters
187+
* @throws GitLabApiException if any exception occurs
188+
*/
189+
public Stream<Event> getAllAuthenticatedUserEventsStream(ActionType action, TargetType targetType,
190+
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
191+
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage(), EventScope.ALL).stream());
113192
}
114193

115194
/**

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ public void testGetAuthenticatedUserEvents() throws GitLabApiException {
6565
assertNotNull(events);
6666
}
6767

68+
@Test
69+
public void testGetAuthenticatedUserEventsWithScope() throws GitLabApiException {
70+
List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, null, null, null, 1, 10, Constants.EventScope.ALL);
71+
assertNotNull(events);
72+
}
73+
74+
@Test
75+
public void testGetAllAuthenticatedUserEvents() throws GitLabApiException {
76+
List<Event> events = gitLabApi.getEventsApi().getAllAuthenticatedUserEvents(null, null, null, null, null);
77+
assertNotNull(events);
78+
}
79+
6880
@Test
6981
public void testGetAuthenticatedUserEventsWithDates() throws GitLabApiException {
7082
Date after = new Date(0);
@@ -77,6 +89,18 @@ public void testGetAuthenticatedUserEventsWithDates() throws GitLabApiException
7789
assertEquals(0, events.size());
7890
}
7991

92+
@Test
93+
public void testGetAuthenticatedUserEventsWithDatesAndScope() throws GitLabApiException {
94+
Date after = new Date(0);
95+
Date now = new Date();
96+
List<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, now, after, null, 1, 10, Constants.EventScope.ALL);
97+
assertNotNull(events);
98+
99+
events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, after, null, null, 1, 10, Constants.EventScope.ALL);
100+
assertNotNull(events);
101+
assertEquals(0, events.size());
102+
}
103+
80104
@Test
81105
public void testGetUserEvents() throws GitLabApiException {
82106
assertNotNull(testUser);
@@ -107,6 +131,12 @@ public void testPagedGetAuthenticatedUserEvents() throws GitLabApiException {
107131
assertNotNull(events);
108132
}
109133

134+
@Test
135+
public void testPagedGetAuthenticatedUserEventsWithScope() throws GitLabApiException {
136+
Pager<Event> events = gitLabApi.getEventsApi().getAuthenticatedUserEvents(null, null, null, null, null, 10, Constants.EventScope.ALL);
137+
assertNotNull(events);
138+
}
139+
110140
@Test
111141
public void testPagedGetUserEvents() throws GitLabApiException {
112142
assertNotNull(testUser);

0 commit comments

Comments
 (0)