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
a4d4c183
Commit
a4d4c183
authored
May 15, 2019
by
Greg Messner
Browse files
Added support for fetching projects with a filter (#356).
parent
c45863b6
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
a4d4c183
...
@@ -479,6 +479,65 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -479,6 +479,65 @@ public class ProjectApi extends AbstractApi implements Constants {
return
(
getStarredProjects
(
getDefaultPerPage
()).
stream
());
return
(
getStarredProjects
(
getDefaultPerPage
()).
stream
());
}
}
/**
* Get a list of all visible projects across GitLab for the authenticated user using the provided filter.
*
* <pre><code>GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a list of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Project
>
getProjects
(
ProjectFilter
filter
)
throws
GitLabApiException
{
return
(
getProjects
(
filter
,
getDefaultPerPage
()).
all
());
}
/**
* Get a list of all visible projects across GitLab for the authenticated user in the specified page range
* using the provided filter.
*
* <pre><code>GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @param page the page to get
* @param perPage the number of projects per page
* @return a list of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Project
>
getProjects
(
ProjectFilter
filter
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
filter
.
getQueryParams
(
page
,
perPage
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Project
>>()
{}));
}
/**
* Get a Pager of all visible projects across GitLab for the authenticated user using the provided filter.
*
* <pre><code>GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public
Pager
<
Project
>
getProjects
(
ProjectFilter
filter
,
int
itemsPerPage
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
filter
.
getQueryParams
();
return
(
new
Pager
<
Project
>(
this
,
Project
.
class
,
itemsPerPage
,
formData
.
asMap
(),
"projects"
));
}
/**
* Get a Stream of all visible projects across GitLab for the authenticated user using the provided filter.
*
* <pre><code>GET /projects</code></pre>
*
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a Stream of all visible projects across GitLab for the authenticated use
* @throws GitLabApiException if any exception occurs
*/
public
Stream
<
Project
>
getProjectsStream
(
ProjectFilter
filter
)
throws
GitLabApiException
{
return
(
getProjects
(
filter
,
getDefaultPerPage
()).
stream
());
}
/**
/**
* Get a list of visible projects owned by the given user.
* Get a list of visible projects owned by the given user.
*
*
...
@@ -486,7 +545,7 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -486,7 +545,7 @@ public class ProjectApi extends AbstractApi implements Constants {
*
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a list of visible projects owned by the given use
* @return a list of visible projects owned by the given use
r
* @throws GitLabApiException if any exception occurs
* @throws GitLabApiException if any exception occurs
*/
*/
public
List
<
Project
>
getUserProjects
(
Object
userIdOrUsername
,
ProjectFilter
filter
)
throws
GitLabApiException
{
public
List
<
Project
>
getUserProjects
(
Object
userIdOrUsername
,
ProjectFilter
filter
)
throws
GitLabApiException
{
...
@@ -502,7 +561,7 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -502,7 +561,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param filter the ProjectFilter instance holding the filter values for the query
* @param filter the ProjectFilter instance holding the filter values for the query
* @param page the page to get
* @param page the page to get
* @param perPage the number of projects per page
* @param perPage the number of projects per page
* @return a list of visible projects owned by the given use
* @return a list of visible projects owned by the given use
r
* @throws GitLabApiException if any exception occurs
* @throws GitLabApiException if any exception occurs
*/
*/
public
List
<
Project
>
getUserProjects
(
Object
userIdOrUsername
,
ProjectFilter
filter
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
public
List
<
Project
>
getUserProjects
(
Object
userIdOrUsername
,
ProjectFilter
filter
,
int
page
,
int
perPage
)
throws
GitLabApiException
{
...
@@ -520,7 +579,7 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -520,7 +579,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @param filter the ProjectFilter instance holding the filter values for the query
* @param itemsPerPage the number of Project instances that will be fetched per page
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of visible projects owned by the given use
* @return a Pager of visible projects owned by the given use
r
* @throws GitLabApiException if any exception occurs
* @throws GitLabApiException if any exception occurs
*/
*/
public
Pager
<
Project
>
getUserProjects
(
Object
userIdOrUsername
,
ProjectFilter
filter
,
int
itemsPerPage
)
throws
GitLabApiException
{
public
Pager
<
Project
>
getUserProjects
(
Object
userIdOrUsername
,
ProjectFilter
filter
,
int
itemsPerPage
)
throws
GitLabApiException
{
...
@@ -536,7 +595,7 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -536,7 +595,7 @@ public class ProjectApi extends AbstractApi implements Constants {
*
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param filter the ProjectFilter instance holding the filter values for the query
* @param filter the ProjectFilter instance holding the filter values for the query
* @return a Stream of visible projects owned by the given use
* @return a Stream of visible projects owned by the given use
r
* @throws GitLabApiException if any exception occurs
* @throws GitLabApiException if any exception occurs
*/
*/
public
Stream
<
Project
>
getUserProjectsStream
(
Object
userIdOrUsername
,
ProjectFilter
filter
)
throws
GitLabApiException
{
public
Stream
<
Project
>
getUserProjectsStream
(
Object
userIdOrUsername
,
ProjectFilter
filter
)
throws
GitLabApiException
{
...
...
src/test/java/org/gitlab4j/api/TestProjectApi.java
View file @
a4d4c183
...
@@ -43,6 +43,7 @@ import org.gitlab4j.api.models.AccessLevel;
...
@@ -43,6 +43,7 @@ import org.gitlab4j.api.models.AccessLevel;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Member
;
import
org.gitlab4j.api.models.Member
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.ProjectFilter
;
import
org.gitlab4j.api.models.Variable
;
import
org.gitlab4j.api.models.Variable
;
import
org.gitlab4j.api.models.Visibility
;
import
org.gitlab4j.api.models.Visibility
;
import
org.junit.AfterClass
;
import
org.junit.AfterClass
;
...
@@ -432,6 +433,24 @@ public class TestProjectApi extends AbstractIntegrationTest {
...
@@ -432,6 +433,24 @@ public class TestProjectApi extends AbstractIntegrationTest {
assertTrue
(
projects
!=
null
);
assertTrue
(
projects
!=
null
);
}
}
@Test
public
void
testProjectsWithFilter
()
throws
GitLabApiException
{
ProjectFilter
filter
=
new
ProjectFilter
().
withOwned
(
true
).
withStatistics
(
false
);
List
<
Project
>
projects
=
gitLabApi
.
getProjectApi
().
getProjects
(
filter
);
assertTrue
(
projects
!=
null
);
assertTrue
(
projects
.
size
()
>
0
);
assertNull
(
projects
.
get
(
0
).
getStatistics
());
}
@Test
public
void
testProjectsWithFilterAndStatistics
()
throws
GitLabApiException
{
ProjectFilter
filter
=
new
ProjectFilter
().
withOwned
(
true
).
withStatistics
(
true
);
List
<
Project
>
projects
=
gitLabApi
.
getProjectApi
().
getProjects
(
filter
);
assertTrue
(
projects
!=
null
);
assertTrue
(
projects
.
size
()
>
0
);
assertNotNull
(
projects
.
get
(
0
).
getStatistics
());
}
@Test
@Test
public
void
testProjectPerPage
()
throws
GitLabApiException
{
public
void
testProjectPerPage
()
throws
GitLabApiException
{
List
<
Project
>
projects
=
gitLabApi
.
getProjectApi
().
getProjects
(
1
,
10
);
List
<
Project
>
projects
=
gitLabApi
.
getProjectApi
().
getProjects
(
1
,
10
);
...
...
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