Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
0947d1fa
Unverified
Commit
0947d1fa
authored
Mar 08, 2022
by
Gautier de Saint Martin Lacaze
Committed by
GitHub
Mar 08, 2022
Browse files
Merge pull request #760 from beekeep/beekeep-patch-event-scope
Added support for scope attribute to EventsApi
parents
c0d17edf
5588ad83
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/Constants.java
View file @
0947d1fa
...
...
@@ -509,7 +509,7 @@ public interface Constants {
/** Enum to use for specifying the event action_type. */
public
enum
ActionType
{
CREATED
,
UPDATED
,
CLOSED
,
REOPENED
,
PUSHED
,
COMMENTED
,
MERGED
,
JOINED
,
LEFT
,
DESTROYED
,
EXPIRED
,
REMOVED
;
CREATED
,
UPDATED
,
OPENED
,
CLOSED
,
REOPENED
,
PUSHED
,
COMMENTED
,
MERGED
,
JOINED
,
LEFT
,
DESTROYED
,
EXPIRED
,
REMOVED
,
DELETED
,
APPROVED
,
ACCEPTED
,
IMPORTED
;
private
static
JacksonJsonEnumHelper
<
ActionType
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
ActionType
.
class
);
...
...
@@ -962,5 +962,27 @@ public interface Constants {
return
(
enumHelper
.
toString
(
this
));
}
}
/** Enum to use for specifying the Event scope. */
public
enum
EventScope
{
ALL
;
private
static
JacksonJsonEnumHelper
<
EventScope
>
enumHelper
=
new
JacksonJsonEnumHelper
<>(
EventScope
.
class
);
@JsonCreator
public
static
EventScope
forValue
(
String
value
)
{
return
enumHelper
.
forValue
(
value
);
}
@JsonValue
public
String
toValue
()
{
return
(
enumHelper
.
toString
(
this
));
}
@Override
public
String
toString
()
{
return
(
enumHelper
.
toString
(
this
));
}
}
}
src/main/java/org/gitlab4j/api/EventsApi.java
View file @
0947d1fa
...
...
@@ -36,6 +36,24 @@ public class EventsApi extends AbstractApi {
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
getDefaultPerPage
()).
all
());
}
/**
* Get a list of all events for the authenticated user, across all of the user's projects.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @return a list of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Event
>
getAllAuthenticatedUserEvents
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
)
throws
GitLabApiException
{
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
getDefaultPerPage
(),
EventScope
.
ALL
).
all
());
}
/**
* Get a list of events for the authenticated user and in the specified page range.
*
...
...
@@ -53,6 +71,27 @@ public class EventsApi extends AbstractApi {
*/
public
List
<
Event
>
getAuthenticatedUserEvents
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
page
,
perPage
,
null
));
}
/**
* Get a list of events for the authenticated user and in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @param page the page to get
* @param perPage the number of projects per page
* @param scope include all events across a user’s projects, optional
* @return a list of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Event
>
getAuthenticatedUserEvents
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
page
,
int
perPage
,
EventScope
scope
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
...
...
@@ -61,7 +100,8 @@ public class EventsApi extends AbstractApi {
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
)
.
withParam
(
PAGE_PARAM
,
page
)
.
withParam
(
PER_PAGE_PARAM
,
perPage
);
.
withParam
(
PER_PAGE_PARAM
,
perPage
)
.
withParam
(
"scope"
,
scope
!=
null
?
scope
.
toValue
().
toLowerCase
()
:
null
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"events"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Event
>>()
{}));
...
...
@@ -83,13 +123,34 @@ public class EventsApi extends AbstractApi {
*/
public
Pager
<
Event
>
getAuthenticatedUserEvents
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
itemsPerPage
)
throws
GitLabApiException
{
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
itemsPerPage
,
null
));
}
/**
* Get a list of events for the authenticated user and in the specified page range.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @param itemsPerPage the number of Event instances that will be fetched per page
* @param scope include all events across a user’s projects, optional
* @return a Pager of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
Event
>
getAuthenticatedUserEvents
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
itemsPerPage
,
EventScope
scope
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
.
withParam
(
"target_type"
,
targetType
!=
null
?
targetType
.
toValue
().
toLowerCase
()
:
null
)
.
withParam
(
"before"
,
before
)
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
);
.
withParam
(
"sort"
,
sortOrder
)
.
withParam
(
"scope"
,
scope
!=
null
?
scope
.
toValue
().
toLowerCase
()
:
null
);
return
(
new
Pager
<
Event
>(
this
,
Event
.
class
,
itemsPerPage
,
formData
.
asMap
(),
"events"
));
}
...
...
@@ -109,7 +170,25 @@ public class EventsApi extends AbstractApi {
*/
public
Stream
<
Event
>
getAuthenticatedUserEventsStream
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
)
throws
GitLabApiException
{
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
getDefaultPerPage
()).
stream
());
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
getDefaultPerPage
(),
null
).
stream
());
}
/**
* Get a Stream of all events for the authenticated user, across all of the user's projects.
*
* <pre><code>GitLab Endpoint: GET /events</code></pre>
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @return a Stream of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
Event
>
getAllAuthenticatedUserEventsStream
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
)
throws
GitLabApiException
{
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
getDefaultPerPage
(),
EventScope
.
ALL
).
stream
());
}
/**
...
...
src/test/java/org/gitlab4j/api/TestEventsApi.java
View file @
0947d1fa
...
...
@@ -65,6 +65,18 @@ public class TestEventsApi extends AbstractIntegrationTest {
assertNotNull
(
events
);
}
@Test
public
void
testGetAuthenticatedUserEventsWithScope
()
throws
GitLabApiException
{
List
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getAuthenticatedUserEvents
(
null
,
null
,
null
,
null
,
null
,
1
,
10
,
Constants
.
EventScope
.
ALL
);
assertNotNull
(
events
);
}
@Test
public
void
testGetAllAuthenticatedUserEvents
()
throws
GitLabApiException
{
List
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getAllAuthenticatedUserEvents
(
null
,
null
,
null
,
null
,
null
);
assertNotNull
(
events
);
}
@Test
public
void
testGetAuthenticatedUserEventsWithDates
()
throws
GitLabApiException
{
Date
after
=
new
Date
(
0
);
...
...
@@ -77,6 +89,18 @@ public class TestEventsApi extends AbstractIntegrationTest {
assertEquals
(
0
,
events
.
size
());
}
@Test
public
void
testGetAuthenticatedUserEventsWithDatesAndScope
()
throws
GitLabApiException
{
Date
after
=
new
Date
(
0
);
Date
now
=
new
Date
();
List
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getAuthenticatedUserEvents
(
null
,
null
,
now
,
after
,
null
,
1
,
10
,
Constants
.
EventScope
.
ALL
);
assertNotNull
(
events
);
events
=
gitLabApi
.
getEventsApi
().
getAuthenticatedUserEvents
(
null
,
null
,
after
,
null
,
null
,
1
,
10
,
Constants
.
EventScope
.
ALL
);
assertNotNull
(
events
);
assertEquals
(
0
,
events
.
size
());
}
@Test
public
void
testGetUserEvents
()
throws
GitLabApiException
{
assertNotNull
(
testUser
);
...
...
@@ -107,6 +131,12 @@ public class TestEventsApi extends AbstractIntegrationTest {
assertNotNull
(
events
);
}
@Test
public
void
testPagedGetAuthenticatedUserEventsWithScope
()
throws
GitLabApiException
{
Pager
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getAuthenticatedUserEvents
(
null
,
null
,
null
,
null
,
null
,
10
,
Constants
.
EventScope
.
ALL
);
assertNotNull
(
events
);
}
@Test
public
void
testPagedGetUserEvents
()
throws
GitLabApiException
{
assertNotNull
(
testUser
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment