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
67043cce
Commit
67043cce
authored
Aug 20, 2017
by
Greg Messner
Browse files
Added getUser(String username) and test for same.
parent
376d5ac1
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/UserApi.java
View file @
67043cce
...
@@ -74,6 +74,24 @@ public class UserApi extends AbstractApi {
...
@@ -74,6 +74,24 @@ public class UserApi extends AbstractApi {
return
(
response
.
readEntity
(
User
.
class
));
return
(
response
.
readEntity
(
User
.
class
));
}
}
/**
* Lookup a user by username.
*
* NOTE: This is for admin users only.
*
* GET /users?username=:username
*
* @param username the username of the user to get
* @return the User instance for the specified username
* @throws GitLabApiException if any exception occurs
*/
public
User
getUser
(
String
username
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"username"
,
username
,
true
);
Response
response
=
get
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"users"
);
List
<
User
>
users
=
response
.
readEntity
(
new
GenericType
<
List
<
User
>>()
{});
return
(
users
.
isEmpty
()
?
null
:
users
.
get
(
0
));
}
/**
/**
* Search users by Email or username
* Search users by Email or username
*
*
...
...
src/test/java/org/gitlab4j/api/TestUserApi.java
View file @
67043cce
...
@@ -82,4 +82,11 @@ public class TestUserApi {
...
@@ -82,4 +82,11 @@ public class TestUserApi {
assertNotNull
(
currentUser
);
assertNotNull
(
currentUser
);
assertEquals
(
TEST_USERNAME
,
currentUser
.
getUsername
());
assertEquals
(
TEST_USERNAME
,
currentUser
.
getUsername
());
}
}
@Test
public
void
testLookupUser
()
throws
GitLabApiException
{
User
user
=
gitLabApi
.
getUserApi
().
getUser
(
TEST_USERNAME
);
assertNotNull
(
user
);
assertEquals
(
TEST_USERNAME
,
user
.
getUsername
());
}
}
}
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