Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/org/gitlab4j/api/ProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,20 @@ public Project createProject(Project project, String importUrl) throws GitLabApi
if (isApiVersion(ApiVersion.V3)) {
boolean isPublic = (project.getPublic() != null ? project.getPublic() : project.getVisibility() == Visibility.PUBLIC);
formData.withParam("public", isPublic);

if (project.getTagList() != null && !project.getTagList().isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to throw the following exception:

IllegalArgumentException("GitLab API v3 does not support tag lists when creating projects")

// What would be the preferred way to deal with this, as the V3 API doesn't
// appear to do anything if you send in the tag_list? Could either just ignore,
// or throw an exception.
}
} else {
Visibility visibility = (project.getVisibility() != null ? project.getVisibility() :
project.getPublic() == Boolean.TRUE ? Visibility.PUBLIC : null);
formData.withParam("visibility", visibility);

if (project.getTagList() != null && !project.getTagList().isEmpty()) {
formData.withParam("tag_list", String.join(",", project.getTagList()));
}
}

if (project.getNamespace() != null) {
Expand Down Expand Up @@ -877,10 +887,20 @@ public Project updateProject(Project project) throws GitLabApiException {
formData.withParam("visibility_level", project.getVisibilityLevel());
boolean isPublic = (project.getPublic() != null ? project.getPublic() : project.getVisibility() == Visibility.PUBLIC);
formData.withParam("public", isPublic);

if (project.getTagList() != null && !project.getTagList().isEmpty()) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above comment about throwing an exception.

// What would be the preferred way to deal with this, as the V3 API doesn't
// appear to do anything if you send in the tag_list? Could either just ignore,
// or throw an exception.
}
} else {
Visibility visibility = (project.getVisibility() != null ? project.getVisibility() :
project.getPublic() == Boolean.TRUE ? Visibility.PUBLIC : null);
formData.withParam("visibility", visibility);

if (project.getTagList() != null && !project.getTagList().isEmpty()) {
formData.withParam("tag_list", String.join(",", project.getTagList()));
}
}

Response response = putWithFormData(Response.Status.OK, formData, "projects", id);
Expand Down
9 changes: 7 additions & 2 deletions src/test/java/org/gitlab4j/api/TestProjectApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -169,7 +170,8 @@ public void testCreate() throws GitLabApiException {
.withMergeRequestsEnabled(true)
.withWikiEnabled(true)
.withSnippetsEnabled(true)
.withVisibility(Visibility.PUBLIC);
.withVisibility(Visibility.PUBLIC)
.withTagList(Arrays.asList("tag1","tag2"));

Project newProject = gitLabApi.getProjectApi().createProject(project);
assertNotNull(newProject);
Expand All @@ -179,6 +181,7 @@ public void testCreate() throws GitLabApiException {
assertEquals(project.getMergeRequestsEnabled(), newProject.getMergeRequestsEnabled());
assertEquals(project.getWikiEnabled(), newProject.getWikiEnabled());
assertEquals(project.getSnippetsEnabled(), newProject.getSnippetsEnabled());
assertEquals(project.getTagList(), newProject.getTagList());
assertTrue(Visibility.PUBLIC == newProject.getVisibility() || Boolean.TRUE == newProject.getPublic());
}

Expand All @@ -192,7 +195,8 @@ public void testUpdate() throws GitLabApiException {
.withMergeRequestsEnabled(true)
.withWikiEnabled(true)
.withSnippetsEnabled(true)
.withVisibility(Visibility.PUBLIC);
.withVisibility(Visibility.PUBLIC)
.withTagList(Arrays.asList("tag1","tag2"));

Project newProject = gitLabApi.getProjectApi().createProject(project);
assertNotNull(newProject);
Expand All @@ -202,6 +206,7 @@ public void testUpdate() throws GitLabApiException {
assertEquals(project.getMergeRequestsEnabled(), newProject.getMergeRequestsEnabled());
assertEquals(project.getWikiEnabled(), newProject.getWikiEnabled());
assertEquals(project.getSnippetsEnabled(), newProject.getSnippetsEnabled());
assertEquals(project.getTagList(), newProject.getTagList());
assertTrue(Visibility.PUBLIC == newProject.getVisibility() || Boolean.TRUE == newProject.getPublic());

project = new Project()
Expand Down