Skip to content

Commit f517be4

Browse files
authored
Merge branch 'master' into json_binding
2 parents 3efc126 + 9401aac commit f517be4

File tree

14 files changed

+271
-46
lines changed

14 files changed

+271
-46
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.gitlab4j.api;
22

33
import java.io.File;
4+
import java.io.InputStream;
45
import java.net.URL;
56

67
import javax.ws.rs.NotAuthorizedException;
@@ -369,7 +370,7 @@ protected Response post(Response.Status expectedStatus, Form formData, URL url)
369370
* @param expectedStatus the HTTP status that should be returned from the server
370371
* @param name the name for the form field that contains the file name
371372
* @param fileToUpload a File instance pointing to the file to upload
372-
* @param mediaType the content-type of the uploaded file, if null will be determined from fileToUpload
373+
* @param mediaType unused; will be removed in the next major version
373374
* @param pathArgs variable list of arguments used to build the URI
374375
* @return a ClientResponse instance with the data returned from the endpoint
375376
* @throws GitLabApiException if any exception occurs during execution
@@ -382,14 +383,22 @@ protected Response upload(Response.Status expectedStatus, String name, File file
382383
}
383384
}
384385

386+
protected Response upload(Response.Status expectedStatus, String name, InputStream inputStream, String filename, String mediaType, Object... pathArgs) throws GitLabApiException {
387+
try {
388+
return validate(getApiClient().upload(name, inputStream, filename, mediaType, pathArgs), expectedStatus);
389+
} catch (Exception e) {
390+
throw handle(e);
391+
}
392+
}
393+
385394
/**
386395
* Perform a file upload with the specified File instance and path objects, returning
387396
* a ClientResponse instance with the data returned from the endpoint.
388397
*
389398
* @param expectedStatus the HTTP status that should be returned from the server
390399
* @param name the name for the form field that contains the file name
391400
* @param fileToUpload a File instance pointing to the file to upload
392-
* @param mediaType the content-type of the uploaded file, if null will be determined from fileToUpload
401+
* @param mediaType unused; will be removed in the next major version
393402
* @param url the fully formed path to the GitLab API endpoint
394403
* @return a ClientResponse instance with the data returned from the endpoint
395404
* @throws GitLabApiException if any exception occurs during execution
@@ -409,7 +418,7 @@ protected Response upload(Response.Status expectedStatus, String name, File file
409418
* @param expectedStatus the HTTP status that should be returned from the server
410419
* @param name the name for the form field that contains the file name
411420
* @param fileToUpload a File instance pointing to the file to upload
412-
* @param mediaType the content-type of the uploaded file, if null will be determined from fileToUpload
421+
* @param mediaType unused; will be removed in the next major version
413422
* @param formData the Form containing the name/value pairs
414423
* @param url the fully formed path to the GitLab API endpoint
415424
* @return a ClientResponse instance with the data returned from the endpoint

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/main/java/org/gitlab4j/api/GitLabApi.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.util.Map;
66
import java.util.Optional;
77
import java.util.WeakHashMap;
8+
import java.util.function.Supplier;
89
import java.util.logging.Level;
910
import java.util.logging.Logger;
1011

@@ -711,6 +712,14 @@ public String getAuthToken() {
711712
return (apiClient.getAuthToken());
712713
}
713714

715+
/**
716+
* Set auth token supplier for gitlab api client.
717+
* @param authTokenSupplier - supplier which provide actual auth token
718+
*/
719+
public void setAuthTokenSupplier(Supplier<String> authTokenSupplier) {
720+
apiClient.setAuthTokenSupplier(authTokenSupplier);
721+
}
722+
714723
/**
715724
* Get the secret token.
716725
*

0 commit comments

Comments
 (0)