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
829f9bb7
Commit
829f9bb7
authored
May 02, 2020
by
Greg Messner
Browse files
Added support for getting inherited member (#557)
parent
63d7192b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GroupApi.java
View file @
829f9bb7
...
...
@@ -778,9 +778,7 @@ public class GroupApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public
Member
getMember
(
Object
groupIdOrPath
,
int
userId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
getDefaultPerPageParam
(),
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"members"
,
userId
);
return
(
response
.
readEntity
(
new
GenericType
<
Member
>()
{}));
return
(
getMember
(
groupIdOrPath
,
userId
,
false
));
}
/**
...
...
@@ -794,7 +792,46 @@ public class GroupApi extends AbstractApi {
*/
public
Optional
<
Member
>
getOptionalMember
(
Object
groupIdOrPath
,
int
userId
)
{
try
{
return
(
Optional
.
ofNullable
(
getMember
(
groupIdOrPath
,
userId
)));
return
(
Optional
.
ofNullable
(
getMember
(
groupIdOrPath
,
userId
,
false
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
/**
* Gets a group team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/all/:user_id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the project ID/user ID pair
* @throws GitLabApiException if any exception occurs
*/
public
Member
getMember
(
Object
groupIdOrPath
,
Integer
userId
,
Boolean
includeInherited
)
throws
GitLabApiException
{
Response
response
;
if
(
includeInherited
)
{
response
=
get
(
Response
.
Status
.
OK
,
null
,
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"members"
,
"all"
,
userId
);
}
else
{
response
=
get
(
Response
.
Status
.
OK
,
null
,
"groups"
,
getGroupIdOrPath
(
groupIdOrPath
),
"members"
,
userId
);
}
return
(
response
.
readEntity
(
Member
.
class
));
}
/**
* Gets a group team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/:user_id</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the group ID/user ID pair as the value of an Optional
*/
public
Optional
<
Member
>
getOptionalMember
(
Object
groupIdOrPath
,
Integer
userId
,
Boolean
includeInherited
)
{
try
{
return
(
Optional
.
ofNullable
(
getMember
(
groupIdOrPath
,
userId
,
includeInherited
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
...
...
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
829f9bb7
...
...
@@ -1540,8 +1540,7 @@ public class ProjectApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs
*/
public
Member
getMember
(
Object
projectIdOrPath
,
Integer
userId
)
throws
GitLabApiException
{
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"members"
,
userId
);
return
(
response
.
readEntity
(
Member
.
class
));
return
(
getMember
(
projectIdOrPath
,
userId
,
false
));
}
/**
...
...
@@ -1555,7 +1554,46 @@ public class ProjectApi extends AbstractApi implements Constants {
*/
public
Optional
<
Member
>
getOptionalMember
(
Object
projectIdOrPath
,
Integer
userId
)
{
try
{
return
(
Optional
.
ofNullable
(
getMember
(
projectIdOrPath
,
userId
)));
return
(
Optional
.
ofNullable
(
getMember
(
projectIdOrPath
,
userId
,
false
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
}
/**
* Gets a project team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/all/:user_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the project ID/user ID pair
* @throws GitLabApiException if any exception occurs
*/
public
Member
getMember
(
Object
projectIdOrPath
,
Integer
userId
,
Boolean
includeInherited
)
throws
GitLabApiException
{
Response
response
;
if
(
includeInherited
)
{
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"members"
,
"all"
,
userId
);
}
else
{
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
getProjectIdOrPath
(
projectIdOrPath
),
"members"
,
userId
);
}
return
(
response
.
readEntity
(
Member
.
class
));
}
/**
* Gets a project team member, optionally including inherited member.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/members/:user_id</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param userId the user ID of the member
* @param includeInherited if true will the member even if inherited thru an ancestor group
* @return the member specified by the project ID/user ID pair as the value of an Optional
*/
public
Optional
<
Member
>
getOptionalMember
(
Object
projectIdOrPath
,
Integer
userId
,
Boolean
includeInherited
)
{
try
{
return
(
Optional
.
ofNullable
(
getMember
(
projectIdOrPath
,
userId
,
includeInherited
)));
}
catch
(
GitLabApiException
glae
)
{
return
(
GitLabApi
.
createOptionalFromException
(
glae
));
}
...
...
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