Skip to content

Commit 358f422

Browse files
committed
Merging tag list related mods from PR #172
2 parents 05e5f53 + 865a863 commit 358f422

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/main/java/org/gitlab4j/api/ProjectApi.java

+20
Original file line numberDiff line numberDiff line change
@@ -649,10 +649,20 @@ public Project createProject(Project project, String importUrl) throws GitLabApi
649649
if (isApiVersion(ApiVersion.V3)) {
650650
boolean isPublic = (project.getPublic() != null ? project.getPublic() : project.getVisibility() == Visibility.PUBLIC);
651651
formData.withParam("public", isPublic);
652+
653+
if (project.getTagList() != null && !project.getTagList().isEmpty()) {
654+
// What would be the preferred way to deal with this, as the V3 API doesn't
655+
// appear to do anything if you send in the tag_list? Could either just ignore,
656+
// or throw an exception.
657+
}
652658
} else {
653659
Visibility visibility = (project.getVisibility() != null ? project.getVisibility() :
654660
project.getPublic() == Boolean.TRUE ? Visibility.PUBLIC : null);
655661
formData.withParam("visibility", visibility);
662+
663+
if (project.getTagList() != null && !project.getTagList().isEmpty()) {
664+
formData.withParam("tag_list", String.join(",", project.getTagList()));
665+
}
656666
}
657667

658668
if (project.getNamespace() != null) {
@@ -880,10 +890,20 @@ public Project updateProject(Project project) throws GitLabApiException {
880890
formData.withParam("visibility_level", project.getVisibilityLevel());
881891
boolean isPublic = (project.getPublic() != null ? project.getPublic() : project.getVisibility() == Visibility.PUBLIC);
882892
formData.withParam("public", isPublic);
893+
894+
if (project.getTagList() != null && !project.getTagList().isEmpty()) {
895+
// What would be the preferred way to deal with this, as the V3 API doesn't
896+
// appear to do anything if you send in the tag_list? Could either just ignore,
897+
// or throw an exception.
898+
}
883899
} else {
884900
Visibility visibility = (project.getVisibility() != null ? project.getVisibility() :
885901
project.getPublic() == Boolean.TRUE ? Visibility.PUBLIC : null);
886902
formData.withParam("visibility", visibility);
903+
904+
if (project.getTagList() != null && !project.getTagList().isEmpty()) {
905+
formData.withParam("tag_list", String.join(",", project.getTagList()));
906+
}
887907
}
888908

889909
Response response = putWithFormData(Response.Status.OK, formData, "projects", id);

src/test/java/org/gitlab4j/api/TestProjectApi.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static org.junit.Assert.assertTrue;
3030
import static org.junit.Assume.assumeTrue;
3131

32+
import java.util.Arrays;
3233
import java.util.List;
3334
import java.util.Optional;
3435

@@ -169,7 +170,8 @@ public void testCreate() throws GitLabApiException {
169170
.withMergeRequestsEnabled(true)
170171
.withWikiEnabled(true)
171172
.withSnippetsEnabled(true)
172-
.withVisibility(Visibility.PUBLIC);
173+
.withVisibility(Visibility.PUBLIC)
174+
.withTagList(Arrays.asList("tag1","tag2"));
173175

174176
Project newProject = gitLabApi.getProjectApi().createProject(project);
175177
assertNotNull(newProject);
@@ -179,6 +181,7 @@ public void testCreate() throws GitLabApiException {
179181
assertEquals(project.getMergeRequestsEnabled(), newProject.getMergeRequestsEnabled());
180182
assertEquals(project.getWikiEnabled(), newProject.getWikiEnabled());
181183
assertEquals(project.getSnippetsEnabled(), newProject.getSnippetsEnabled());
184+
assertEquals(project.getTagList(), newProject.getTagList());
182185
assertTrue(Visibility.PUBLIC == newProject.getVisibility() || Boolean.TRUE == newProject.getPublic());
183186
}
184187

@@ -192,7 +195,8 @@ public void testUpdate() throws GitLabApiException {
192195
.withMergeRequestsEnabled(true)
193196
.withWikiEnabled(true)
194197
.withSnippetsEnabled(true)
195-
.withVisibility(Visibility.PUBLIC);
198+
.withVisibility(Visibility.PUBLIC)
199+
.withTagList(Arrays.asList("tag1","tag2"));
196200

197201
Project newProject = gitLabApi.getProjectApi().createProject(project);
198202
assertNotNull(newProject);
@@ -202,6 +206,7 @@ public void testUpdate() throws GitLabApiException {
202206
assertEquals(project.getMergeRequestsEnabled(), newProject.getMergeRequestsEnabled());
203207
assertEquals(project.getWikiEnabled(), newProject.getWikiEnabled());
204208
assertEquals(project.getSnippetsEnabled(), newProject.getSnippetsEnabled());
209+
assertEquals(project.getTagList(), newProject.getTagList());
205210
assertTrue(Visibility.PUBLIC == newProject.getVisibility() || Boolean.TRUE == newProject.getPublic());
206211

207212
project = new Project()

0 commit comments

Comments
 (0)