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
a42bc84e
Commit
a42bc84e
authored
Apr 14, 2017
by
Greg Messner
Browse files
Added support for /namespaces calls.
parent
ec7f44a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
a42bc84e
...
@@ -47,6 +47,7 @@ Available Sub APIs
...
@@ -47,6 +47,7 @@ Available Sub APIs
CommitsApi
CommitsApi
GroupApi
GroupApi
MergeRequestApi
MergeRequestApi
NamespaceApi
ProjectApi
ProjectApi
RepositoryApi
RepositoryApi
RepositoryFileApi
RepositoryFileApi
...
@@ -70,7 +71,13 @@ List<Group> groups = gitLabApi.getGroupApi().getGroups();
...
@@ -70,7 +71,13 @@ List<Group> groups = gitLabApi.getGroupApi().getGroups();
MergeRequestApi:
MergeRequestApi:
```
java
```
java
// Get a list of the merge requests for the specified project
// 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:
ProjectApi:
...
...
src/main/java/org/gitlab4j/api/NamespaceApi.java
View file @
a42bc84e
package
org.gitlab4j.api
;
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
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.
* This class implements the client side API for the GitLab namespace calls.
...
@@ -15,28 +17,33 @@ public class NamespaceApi extends AbstractApi {
...
@@ -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
* @return a List of Namespace instances
* @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
* @throws GitLabApiException if any exception occurs
* @throws GitLabApiException if any exception occurs
*/
*/
public
Session
login
(
String
username
,
String
email
,
String
password
)
throws
GitLabApiException
{
public
List
<
Namespace
>
getNamespaces
()
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"namespaces"
);
if
((
username
==
null
||
username
.
trim
().
length
()
==
0
)
&&
(
email
==
null
||
email
.
trim
().
length
()
==
0
))
{
return
(
response
.
readEntity
(
new
GenericType
<
List
<
Namespace
>>()
{
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
);
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
>>()
{
}));
}
}
}
}
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