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
6753e62f
Commit
6753e62f
authored
Dec 27, 2017
by
Greg Messner
Browse files
Added share project support (#112).
parent
1790d4db
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/main/java/org/gitlab4j/api/ProjectApi.java
View file @
6753e62f
...
@@ -1664,4 +1664,38 @@ public class ProjectApi extends AbstractApi implements Constants {
...
@@ -1664,4 +1664,38 @@ public class ProjectApi extends AbstractApi implements Constants {
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
projectId
,
"snippets"
,
snippetId
,
"raw"
);
Response
response
=
get
(
Response
.
Status
.
OK
,
null
,
"projects"
,
projectId
,
"snippets"
,
snippetId
,
"raw"
);
return
(
response
.
readEntity
(
String
.
class
));
return
(
response
.
readEntity
(
String
.
class
));
}
}
/**
* Share a project with the specified group.
*
* POST /projects/:id/share
*
* @param projectId the ID of the project to share, required
* @param groupId the ID of the group to share with, required
* @param accessLevel the permissions level to grant the group, required
* @param expiresAt the share expiration date, optional
* @throws GitLabApiException if any exception occurs
*/
public
void
shareProject
(
Integer
projectId
,
Integer
groupId
,
AccessLevel
accessLevel
,
Date
expiresAt
)
throws
GitLabApiException
{
GitLabApiForm
formData
=
new
GitLabApiForm
()
.
withParam
(
"group_id"
,
groupId
,
true
)
.
withParam
(
"group_access"
,
accessLevel
.
toValue
(),
true
)
.
withParam
(
"expires_at"
,
expiresAt
);
post
(
Response
.
Status
.
CREATED
,
formData
,
"projects"
,
projectId
,
"share"
);
}
/**
* Unshare the project from the group.
*
* DELETE /projects/:id/share/:group_id
*
* @param projectId the ID of the project to unshare, required
* @param groupId the ID of the group to unshare, required
* @throws GitLabApiException if any exception occurs
*/
public
void
unshareProject
(
Integer
projectId
,
Integer
groupId
)
throws
GitLabApiException
{
Response
.
Status
expectedStatus
=
(
isApiVersion
(
ApiVersion
.
V3
)
?
Response
.
Status
.
OK
:
Response
.
Status
.
NO_CONTENT
);
delete
(
expectedStatus
,
null
,
"projects"
,
projectId
,
"share"
,
groupId
);
}
}
}
src/test/java/org/gitlab4j/api/TestProjectApi.java
View file @
6753e62f
...
@@ -31,6 +31,8 @@ import static org.junit.Assume.assumeTrue;
...
@@ -31,6 +31,8 @@ import static org.junit.Assume.assumeTrue;
import
java.util.List
;
import
java.util.List
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.GitLabApi.ApiVersion
;
import
org.gitlab4j.api.models.AccessLevel
;
import
org.gitlab4j.api.models.Group
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.Project
;
import
org.gitlab4j.api.models.Visibility
;
import
org.gitlab4j.api.models.Visibility
;
import
org.junit.AfterClass
;
import
org.junit.AfterClass
;
...
@@ -129,6 +131,15 @@ public class TestProjectApi {
...
@@ -129,6 +131,15 @@ public class TestProjectApi {
gitLabApi
.
getProjectApi
().
deleteProject
(
project
);
gitLabApi
.
getProjectApi
().
deleteProject
(
project
);
}
catch
(
GitLabApiException
ignore
)
{}
}
catch
(
GitLabApiException
ignore
)
{}
if
(
TEST_GROUP
!=
null
&&
TEST_PROJECT_NAME
!=
null
)
{
try
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
List
<
Group
>
groups
=
gitLabApi
.
getGroupApi
().
getGroups
(
TEST_GROUP
);
gitLabApi
.
getProjectApi
().
unshareProject
(
project
.
getId
(),
groups
.
get
(
0
).
getId
());
}
catch
(
GitLabApiException
ignore
)
{
}
}
if
(
TEST_GROUP
!=
null
&&
TEST_GROUP_PROJECT
!=
null
)
{
if
(
TEST_GROUP
!=
null
&&
TEST_GROUP_PROJECT
!=
null
)
{
try
{
try
{
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_GROUP_PROJECT
);
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_GROUP_PROJECT
);
...
@@ -407,4 +418,21 @@ public class TestProjectApi {
...
@@ -407,4 +418,21 @@ public class TestProjectApi {
Project
forkedProject
=
gitLabApi
.
getProjectApi
().
forkProject
(
project
.
getId
(),
TEST_NAMESPACE
);
Project
forkedProject
=
gitLabApi
.
getProjectApi
().
forkProject
(
project
.
getId
(),
TEST_NAMESPACE
);
assertNotNull
(
forkedProject
);
assertNotNull
(
forkedProject
);
}
}
@Test
public
void
testShareProject
()
throws
GitLabApiException
{
assumeTrue
(
TEST_GROUP
!=
null
&&
TEST_GROUP_PROJECT
!=
null
);
assumeTrue
(
TEST_GROUP
.
trim
().
length
()
>
0
&&
TEST_GROUP_PROJECT
.
trim
().
length
()
>
0
);
Project
project
=
gitLabApi
.
getProjectApi
().
getProject
(
TEST_NAMESPACE
,
TEST_PROJECT_NAME
);
assertNotNull
(
project
);
List
<
Group
>
groups
=
gitLabApi
.
getGroupApi
().
getGroups
(
TEST_GROUP
);
assertNotNull
(
groups
);
Group
shareGroup
=
groups
.
get
(
0
);
gitLabApi
.
getProjectApi
().
shareProject
(
project
.
getId
(),
shareGroup
.
getId
(),
AccessLevel
.
DEVELOPER
,
null
);
gitLabApi
.
getProjectApi
().
unshareProject
(
project
.
getId
(),
shareGroup
.
getId
());
}
}
}
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