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
a42bc84e
Commit
a42bc84e
authored
8 years ago
by
Greg Messner
Browse files
Options
Download
Email Patches
Plain Diff
Added support for /namespaces calls.
parent
ec7f44a2
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
README.md
+8
-1
README.md
src/main/java/org/gitlab4j/api/NamespaceApi.java
+27
-20
src/main/java/org/gitlab4j/api/NamespaceApi.java
with
35 additions
and
21 deletions
+35
-21
README.md
+
8
-
1
View file @
a42bc84e
...
...
@@ -47,6 +47,7 @@ Available Sub APIs
CommitsApi
GroupApi
MergeRequestApi
NamespaceApi
ProjectApi
RepositoryApi
RepositoryFileApi
...
...
@@ -70,7 +71,13 @@ List<Group> groups = gitLabApi.getGroupApi().getGroups();
MergeRequestApi:
```
java
// Get a list of the merge requests for the specified project
List
<
MergeRequest
>
mregeRequests
=
gitLabApi
.
getMergeRequestApi
().
getMergeRequests
(
1234
);
List
<
MergeRequest
>
mergeRequests
=
gitLabApi
.
getMergeRequestApi
().
getMergeRequests
(
1234
);
```
NamespaceApi:
```
java
// Get all namespaces that match "foobar" in their name or path
List
<
Namespace
>
namespaces
=
gitLabApi
.
getNamespaceApi
().
findNamespaces
(
"foobar"
);
```
ProjectApi:
...
...
This diff is collapsed.
Click to expand it.
src/main/java/org/gitlab4j/api/NamespaceApi.java
+
27
-
20
View file @
a42bc84e
package
org.gitlab4j.api
;
import
javax.ws.rs.core.Form
;
import
java.util.List
;
import
javax.ws.rs.core.GenericType
;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.models.
Session
;
import
org.gitlab4j.api.models.
Namespace
;
/**
* This class implements the client side API for the GitLab namespace calls.
...
...
@@ -15,28 +17,33 @@ public class NamespaceApi extends AbstractApi {
}
/**
* Login to get private token.
* Get a list of the namespaces of the authenticated user. If the user is an administrator,
* a list of all namespaces in the GitLab instance is shown.
*
*
POST /session
*
GET /namespaces
*
* @param username the username to login
* @param email the email address to login
* @param password the password of the user
* @return a Session instance with info on the logged in user
* @return a List of Namespace instances
* @throws GitLabApiException if any exception occurs
*/
public
Session
login
(
String
username
,
String
email
,
String
password
)
throws
GitLabApiException
{
if
((
username
==
null
||
username
.
trim
().
length
()
==
0
)
&&
(
email
==
null
||
email
.
trim
().
length
()
==
0
))
{
throw
new
IllegalArgumentException
(
"both username and email cannot be empty or null"
);
}
Form
formData
=
new
Form
();
addFormParam
(
formData
,
"email"
,
email
,
false
);
addFormParam
(
formData
,
"password"
,
password
,
true
);
addFormParam
(
formData
,
"login"
,
username
,
false
);
public
List
<
Namespace
>
getNamespaces
()
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"namespaces"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Namespace
>>()
{
}));
}
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"session"
);
return
(
response
.
readEntity
(
Session
.
class
));
/**
* Get all namespaces that match a string in their name or path.
*
* GET /namespaces?search=:query
*
* @param query the search string
* @return the Namespace List with the matching namespaces
* @throws GitLabApiException if any exception occurs
*/
public
List
<
Namespace
>
findNamespaces
(
String
query
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"search"
,
query
,
true
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"namespaces"
);
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Namespace
>>()
{
}));
}
}
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