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
f6965d33
Commit
f6965d33
authored
Dec 07, 2017
by
Greg Messner
Browse files
Added updateMember() methods (#103).
parent
2aa68d2f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/GroupApi.java
View file @
f6965d33
package
org.gitlab4j.api
;
import
java.util.Date
;
import
java.util.List
;
import
javax.ws.rs.core.Form
;
...
...
@@ -7,6 +8,7 @@ import javax.ws.rs.core.GenericType;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.AccessLevel
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Member
;
import
org.gitlab4j.api.models.Project
;
...
...
@@ -359,32 +361,146 @@ public class GroupApi extends AbstractApi {
*
* POST /groups/:id/members
*
* @param groupId the project ID to add the member to
* @param userId the user ID of the member to add
* @param accessLevel the access level for the new member
* @param groupId the project ID to add the member to
, required
* @param userId the user ID of the member to add
, required
* @param accessLevel the access level for the new member
, required
* @return a Member instance for the added user
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
groupId
,
Integer
userId
,
Integer
accessLevel
)
throws
GitLabApiException
{
return
(
addMember
(
groupId
,
userId
,
accessLevel
,
null
));
}
Form
formData
=
new
Form
();
formData
.
param
(
"user_id"
,
userId
.
toString
());
formData
.
param
(
"access_level"
,
accessLevel
.
toString
());
/**
* Adds a user to the list of group members.
*
* POST /groups/:id/members
*
* @param groupId the project ID to add the member to, required
* @param userId the user ID of the member to add, required
* @param accessLevel the access level for the new member, required
* @return a Member instance for the added user
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
groupId
,
Integer
userId
,
AccessLevel
accessLevel
)
throws
GitLabApiException
{
return
(
addMember
(
groupId
,
userId
,
accessLevel
.
toValue
(),
null
));
}
/**
* Adds a user to the list of group members.
*
* POST /groups/:id/members
*
* @param groupId the project ID to add the member to, required
* @param userId the user ID of the member to add, required
* @param accessLevel the access level for the new member, required
* @param expiresAt the date the membership in the group will expire, optional
* @return a Member instance for the added user
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
groupId
,
Integer
userId
,
AccessLevel
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
return
(
addMember
(
groupId
,
userId
,
accessLevel
.
toValue
(),
expiresAt
));
}
/**
* Adds a user to the list of group members.
*
* POST /groups/:id/members
*
* @param groupId the project ID to add the member to, required
* @param userId the user ID of the member to add, required
* @param accessLevel the access level for the new member, required
* @param expiresAt the date the membership in the group will expire, optional
* @return a Member instance for the added user
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
groupId
,
Integer
userId
,
Integer
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"user_id"
,
userId
,
true
)
.
withParam
(
"access_level"
,
accessLevel
,
true
)
.
withParam
(
"expires_at"
,
expiresAt
,
false
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"groups"
,
groupId
,
"members"
);
return
(
response
.
readEntity
(
Member
.
class
));
}
/**
* Removes member from the group team.
* Updates a member of a group.
*
* PUT /groups/:groupId/members/:userId
*
* @param groupId the group ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
groupId
,
Integer
userId
,
Integer
accessLevel
)
throws
GitLabApiException
{
return
(
updateMember
(
groupId
,
userId
,
accessLevel
,
null
));
}
/**
* Updates a member of a group.
*
* PUT /groups/:groupId/members/:userId
*
* @param groupId the group ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
groupId
,
Integer
userId
,
AccessLevel
accessLevel
)
throws
GitLabApiException
{
return
(
updateMember
(
groupId
,
userId
,
accessLevel
.
toValue
(),
null
));
}
/**
* Updates a member of a group.
*
* PUT /groups/:groupId/members/:userId
*
* @param groupId the group ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @param expiresAt the date the membership in the group will expire, optional
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
groupId
,
Integer
userId
,
AccessLevel
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
return
(
updateMember
(
groupId
,
userId
,
accessLevel
.
toValue
(),
expiresAt
));
}
/**
* Updates a member of a group.
*
* PUT /groups/:groupId/members/:userId
*
* @param groupId the group ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @param expiresAt the date the membership in the group will expire, optional
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
groupId
,
Integer
userId
,
Integer
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"access_level"
,
accessLevel
,
true
)
.
withParam
(
"expires_at"
,
expiresAt
,
false
);
Response
response
=
put
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"groups"
,
groupId
,
"members"
,
userId
);
return
(
response
.
readEntity
(
Member
.
class
));
}
/**
* Removes member from the group.
*
* DELETE /groups/:id/members/:user_id
*
* @param
p
ro
ject
Id the
p
ro
ject
ID to remove the member from
* @param
g
ro
up
Id the
g
ro
up
ID to remove the member from
* @param userId the user ID of the member to remove
* @throws GitLabApiException if any exception occurs
*/
public
void
removeMember
(
Integer
p
ro
ject
Id
,
Integer
userId
)
throws
GitLabApiException
{
public
void
removeMember
(
Integer
g
ro
up
Id
,
Integer
userId
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
NO_CONTENT
);
delete
(
expectedStatus
,
null
,
"groups"
,
p
ro
ject
Id
,
"members"
,
userId
);
delete
(
expectedStatus
,
null
,
"groups"
,
g
ro
up
Id
,
"members"
,
userId
);
}
}
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
f6965d33
...
...
@@ -25,6 +25,7 @@ package org.gitlab4j.api;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.util.Date
;
import
java.util.List
;
import
javax.ws.rs.core.Form
;
...
...
@@ -32,6 +33,7 @@ import javax.ws.rs.core.GenericType;
import
javax.ws.rs.core.Response
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.AccessLevel
;
import
org.gitlab4j.api.models.Event
;
import
org.gitlab4j.api.models.Issue
;
import
org.gitlab4j.api.models.Member
;
...
...
@@ -959,6 +961,40 @@ public class ProjectApi extends AbstractApi implements Constants {
return
(
response
.
readEntity
(
Member
.
class
));
}
/**
* Adds a user to a project team. This is an idempotent method and can be called multiple times
* with the same parameters. Adding team membership to a user that is already a member does not
* affect the existing membership.
*
* POST /projects/:id/members
*
* @param projectId the project ID to add the team member to, required
* @param userId the user ID of the member to add, required
* @param accessLevel the access level for the new member, required
* @return the added member
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
projectId
,
Integer
userId
,
Integer
accessLevel
)
throws
GitLabApiException
{
return
(
addMember
(
projectId
,
userId
,
accessLevel
,
null
));
}
/**
* Adds a user to a project team. This is an idempotent method and can be called multiple times
* with the same parameters. Adding team membership to a user that is already a member does not
* affect the existing membership.
*
* POST /projects/:id/members
*
* @param projectId the project ID to add the team member to, required
* @param userId the user ID of the member to add, required
* @param accessLevel the access level for the new member, required
* @return the added member
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
projectId
,
Integer
userId
,
AccessLevel
accessLevel
)
throws
GitLabApiException
{
return
(
addMember
(
projectId
,
userId
,
accessLevel
.
toValue
(),
null
));
}
/**
* Adds a user to a project team. This is an idempotent method and can be called multiple times
* with the same parameters. Adding team membership to a user that is already a member does not
...
...
@@ -969,15 +1005,103 @@ public class ProjectApi extends AbstractApi implements Constants {
* @param projectId the project ID to add the team member to
* @param userId the user ID of the member to add
* @param accessLevel the access level for the new member
* @param expiresAt the date the membership in the group will expire
* @return the added member
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
projectId
,
Integer
userId
,
Integer
accessLevel
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
().
withParam
(
"user_id"
,
userId
,
true
).
withParam
(
"access_level"
,
accessLevel
,
true
);
public
Member
addMember
(
Integer
projectId
,
Integer
userId
,
AccessLevel
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
return
(
addMember
(
projectId
,
userId
,
accessLevel
.
toValue
(),
expiresAt
));
}
/**
* Adds a user to a project team. This is an idempotent method and can be called multiple times
* with the same parameters. Adding team membership to a user that is already a member does not
* affect the existing membership.
*
* POST /projects/:id/members
*
* @param projectId the project ID to add the team member to
* @param userId the user ID of the member to add
* @param accessLevel the access level for the new member
* @param expiresAt the date the membership in the group will expire
* @return the added member
* @throws GitLabApiException if any exception occurs
*/
public
Member
addMember
(
Integer
projectId
,
Integer
userId
,
Integer
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"user_id"
,
userId
,
true
)
.
withParam
(
"access_level"
,
accessLevel
,
true
)
.
withParam
(
"expires_at"
,
expiresAt
,
false
);
Response
response
=
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"members"
);
return
(
response
.
readEntity
(
Member
.
class
));
}
/**
* Updates a member of a project.
*
* PUT /projects/:projectId/members/:userId
*
* @param projectId the project ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
projectId
,
Integer
userId
,
Integer
accessLevel
)
throws
GitLabApiException
{
return
(
updateMember
(
projectId
,
userId
,
accessLevel
,
null
));
}
/**
* Updates a member of a project.
*
* PUT /projects/:projectId/members/:userId
*
* @param projectId the project ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
projectId
,
Integer
userId
,
AccessLevel
accessLevel
)
throws
GitLabApiException
{
return
(
updateMember
(
projectId
,
userId
,
accessLevel
.
toValue
(),
null
));
}
/**
* Updates a member of a project.
*
* PUT /projects/:projectId/members/:userId
*
* @param projectId the project ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @param expiresAt the date the membership in the group will expire, optional
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
projectId
,
Integer
userId
,
AccessLevel
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
return
(
updateMember
(
projectId
,
userId
,
accessLevel
.
toValue
(),
expiresAt
));
}
/**
* Updates a member of a project.
*
* PUT /projects/:projectId/members/:userId
*
* @param projectId the project ID the member belongs to, required
* @param userId the user ID of the member to update, required
* @param accessLevel the new access level for the member, required
* @param expiresAt the date the membership in the group will expire, optional
* @return the updated member
* @throws GitLabApiException if any exception occurs
*/
public
Member
updateMember
(
Integer
projectId
,
Integer
userId
,
Integer
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"access_level"
,
accessLevel
,
true
)
.
withParam
(
"expires_at"
,
expiresAt
,
false
);
Response
response
=
put
(
Response
.
Status
.
OK
,
formData
.
asMap
(),
"projects"
,
projectId
,
"members"
,
userId
);
return
(
response
.
readEntity
(
Member
.
class
));
}
/**
* Removes user from project team.
*
...
...
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