Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
佳 邓
Gitlab4j Api
Commits
c50c87cd
Commit
c50c87cd
authored
7 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Initial check-in (#60).
parent
d1f71c0a
main
5.0.x
5.0.x.jdk17
6.x
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/org/gitlab4j/api/EventsApi.java
+269
-0
src/main/java/org/gitlab4j/api/EventsApi.java
src/test/java/org/gitlab4j/api/TestEventsApi.java
+129
-0
src/test/java/org/gitlab4j/api/TestEventsApi.java
with
398 additions
and
0 deletions
+398
-0
src/main/java/org/gitlab4j/api/EventsApi.java
0 → 100644
+
269
-
0
View file @
c50c87cd
package
org.gitlab4j.api
;
import
java.util.Date
;
import
java.util.List
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.Event
;
/**
* This class implements the client side API for the GitLab events calls.
*/
public
class
EventsApi
extends
AbstractApi
{
public
EventsApi
(
GitLabApi
gitLabApi
)
{
super
(
gitLabApi
);
}
/**
* Get a list of events for the authenticated user.
*
* GET /events
*
* @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
>
getAuthenticatedUserEvents
(
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
)
throws
GitLabApiException
{
return
(
getAuthenticatedUserEvents
(
action
,
targetType
,
before
,
after
,
sortOrder
,
1
,
getDefaultPerPage
()));
}
/**
* Get a list of events for the authenticated user and in the specified page range.
*
* GET /events
*
* @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
* @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
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
.
withParam
(
"target_type"
,
targetType
)
.
withParam
(
"before"
,
before
)
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
)
.
withParam
(
PAGE_PARAM
,
page
)
.
withParam
(
PER_PAGE_PARAM
,
perPage
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"events"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Event
>>()
{}));
}
/**
* Get a list of events for the authenticated user and in the specified page range.
*
* GET /events
*
* @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
* @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
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
.
withParam
(
"target_type"
,
targetType
)
.
withParam
(
"before"
,
before
)
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
);
return
(
new
Pager
<
Event
>(
this
,
Event
.
class
,
itemsPerPage
,
formData
.
asMap
(),
"events"
));
}
/**
* Get a list of events for the specified user.
*
* GET /users/:userId/events
*
* @param userId the user ID to get the events for, required
* @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 specified user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Event
>
getUserEvents
(
Integer
userId
,
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
)
throws
GitLabApiException
{
return
(
getUserEvents
(
userId
,
action
,
targetType
,
before
,
after
,
sortOrder
,
1
,
getDefaultPerPage
()));
}
/**
* Get a list of events for the specified user and in the specified page range.
*
* GET /users/:userId/events
*
* @param userId the user ID to get the events for, required
* @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
* @return a list of events for the specified user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Event
>
getUserEvents
(
Integer
userId
,
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
if
(
userId
==
null
)
{
throw
new
RuntimeException
(
"user ID cannot be null"
);
}
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
.
withParam
(
"target_type"
,
targetType
)
.
withParam
(
"before"
,
before
)
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
)
.
withParam
(
PAGE_PARAM
,
page
)
.
withParam
(
PER_PAGE_PARAM
,
perPage
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"users"
,
userId
,
"events"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Event
>>()
{}));
}
/**
* Get a list of events for the specified user and in the specified page range.
*
* GET /users/:userId/events
*
* @param userId the user ID to get the events for, required
* @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
* @return a Pager of events for the specified user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
Event
>
getUserEvents
(
Integer
userId
,
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
itemsPerPage
)
throws
GitLabApiException
{
if
(
userId
==
null
)
{
throw
new
RuntimeException
(
"user ID cannot be null"
);
}
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
.
withParam
(
"target_type"
,
targetType
)
.
withParam
(
"before"
,
before
)
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
);
return
(
new
Pager
<
Event
>(
this
,
Event
.
class
,
itemsPerPage
,
formData
.
asMap
(),
"users"
,
userId
,
"events"
));
}
/**
* Get a list of events for the specified project.
*
* GET /:projectId/events
*
* @param projectId the project ID to get the events for, required
* @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 specified project and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Event
>
getProjectEvents
(
Integer
projectId
,
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
)
throws
GitLabApiException
{
return
(
getProjectEvents
(
projectId
,
action
,
targetType
,
before
,
after
,
sortOrder
,
1
,
getDefaultPerPage
()));
}
/**
* Get a list of events for the specified project and in the specified page range.
*
* GET /projects/:projectId/events
*
* @param projectId the project ID to get the events for, required
* @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
* @return a list of events for the specified project and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Event
>
getProjectEvents
(
Integer
projectId
,
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
if
(
projectId
==
null
)
{
throw
new
RuntimeException
(
"project ID cannot be null"
);
}
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
.
withParam
(
"target_type"
,
targetType
)
.
withParam
(
"before"
,
before
)
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
)
.
withParam
(
PAGE_PARAM
,
page
)
.
withParam
(
PER_PAGE_PARAM
,
perPage
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"events"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Event
>>()
{}));
}
/**
* Get a list of events for the specified project and in the specified page range.
*
* GET /projects/:projectId/events
*
* @param projectId the project ID to get the events for, required
* @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
* @return a Pager of events for the specified project and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
Event
>
getProjectEvents
(
Integer
projectId
,
ActionType
action
,
TargetType
targetType
,
Date
before
,
Date
after
,
SortOrder
sortOrder
,
int
itemsPerPage
)
throws
GitLabApiException
{
if
(
projectId
==
null
)
{
throw
new
RuntimeException
(
"project ID cannot be null"
);
}
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"action"
,
action
)
.
withParam
(
"target_type"
,
targetType
)
.
withParam
(
"before"
,
before
)
.
withParam
(
"after"
,
after
)
.
withParam
(
"sort"
,
sortOrder
);
return
(
new
Pager
<
Event
>(
this
,
Event
.
class
,
itemsPerPage
,
formData
.
asMap
(),
"projects"
,
projectId
,
"events"
));
}
}
This diff is collapsed.
Click to expand it.
src/test/java/org/gitlab4j/api/TestEventsApi.java
0 → 100644
+
129
-
0
View file @
c50c87cd
package
org.gitlab4j.api
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assume
.
assumeTrue
;
import
java.util.List
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.Event
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.User
;
import
org.junit.Before
;
import
org.junit.BeforeClass
;
import
org.junit.Test
;
/**
* In order for these tests to run you must set the following properties in test-gitlab4j.properties
*
* TEST_NAMESPACE
* TEST_PROJECT_NAME
* TEST_HOST_URL
* TEST_PRIVATE_TOKEN
*
* If any of the above are NULL, all tests in this class will be skipped.
*/
public
class
TestEventsApi
{
// The following needs to be set to your test repository
private
static
final
String
TEST_PROJECT_NAME
;
private
static
final
String
TEST_NAMESPACE
;
private
static
final
String
TEST_HOST_URL
;
private
static
final
String
TEST_PRIVATE_TOKEN
;
static
{
TEST_NAMESPACE
=
TestUtils
.
getProperty
(
"TEST_NAMESPACE"
);
TEST_PROJECT_NAME
=
TestUtils
.
getProperty
(
"TEST_PROJECT_NAME"
);
TEST_HOST_URL
=
TestUtils
.
getProperty
(
"TEST_HOST_URL"
);
TEST_PRIVATE_TOKEN
=
TestUtils
.
getProperty
(
"TEST_PRIVATE_TOKEN"
);
}
private
static
GitLabApi
gitLabApi
;
public
TestEventsApi
()
{
super
();
}
@BeforeClass
public
static
void
setup
()
{
String
problems
=
""
;
if
(
TEST_NAMESPACE
==
null
||
TEST_NAMESPACE
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_NAMESPACE cannot be empty\n"
;
}
if
(
TEST_PROJECT_NAME
==
null
||
TEST_PROJECT_NAME
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_PROJECT_NAME cannot be empty\n"
;
}
if
(
TEST_HOST_URL
==
null
||
TEST_HOST_URL
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_HOST_URL cannot be empty\n"
;
}
if
(
TEST_PRIVATE_TOKEN
==
null
||
TEST_PRIVATE_TOKEN
.
trim
().
length
()
==
0
)
{
problems
+=
"TEST_PRIVATE_TOKEN cannot be empty\n"
;
}
if
(
problems
.
isEmpty
())
{
gitLabApi
=
new
GitLabApi
(
ApiVersion
.
V4
,
TEST_HOST_URL
,
TEST_PRIVATE_TOKEN
);
}
else
{
System
.
err
.
print
(
problems
);
}
}
@Before
public
void
beforeMethod
()
{
assumeTrue
(
gitLabApi
!=
null
);
}
@Test
public
void
testGetAuthenticatedUserEvents
()
throws
GitLabApiException
{
List
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getAuthenticatedUserEvents
(
null
,
null
,
null
,
null
,
null
);
assertNotNull
(
events
);
}
@Test
public
void
testGetUserEvents
()
throws
GitLabApiException
{
User
user
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
assertNotNull
(
user
);
List
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getUserEvents
(
user
.
getId
(),
null
,
null
,
null
,
null
,
null
);
assertNotNull
(
events
);
}
@Test
public
void
testGetProjectEvents
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
List
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getProjectEvents
(
project
.
getId
(),
null
,
null
,
null
,
null
,
null
);
assertNotNull
(
events
);
}
@Test
public
void
testPagedGetAuthenticatedUserEvents
()
throws
GitLabApiException
{
Pager
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getAuthenticatedUserEvents
(
null
,
null
,
null
,
null
,
null
,
10
);
assertNotNull
(
events
);
}
@Test
public
void
testPagedGetUserEvents
()
throws
GitLabApiException
{
User
user
=
gitLabApi
.
getUserApi
().
getCurrentUser
();
assertNotNull
(
user
);
Pager
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getUserEvents
(
user
.
getId
(),
null
,
null
,
null
,
null
,
null
,
10
);
assertNotNull
(
events
);
}
@Test
public
void
testPagedGetProjectEvents
()
throws
GitLabApiException
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
Pager
<
Event
>
events
=
gitLabApi
.
getEventsApi
().
getProjectEvents
(
project
.
getId
(),
null
,
null
,
null
,
null
,
null
,
10
);
assertNotNull
(
events
);
}
}
This diff is collapsed.
Click to expand it.
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
Menu
Explore
Projects
Groups
Snippets