diff --git a/self-core-impl/src/main/java/com/selfxdsd/core/GitlabRepo.java b/self-core-impl/src/main/java/com/selfxdsd/core/GitlabRepo.java
index 603c3d78..0292e5b2 100644
--- a/self-core-impl/src/main/java/com/selfxdsd/core/GitlabRepo.java
+++ b/self-core-impl/src/main/java/com/selfxdsd/core/GitlabRepo.java
@@ -26,7 +26,9 @@
import com.selfxdsd.api.Labels;
import com.selfxdsd.api.storage.Storage;
+import javax.json.Json;
import javax.json.JsonObject;
+import java.net.HttpURLConnection;
import java.net.URI;
/**
@@ -34,9 +36,6 @@
* @author criske
* @version $Id$
* @since 0.0.1
- * @todo #1246:60min Implement enabling of Issues for a GitLab repository.
- * If GitLab doesn't support this functionality, the method should not do
- * anything.
*/
final class GitlabRepo extends BaseRepo {
@@ -149,9 +148,29 @@ public String fullName() {
return this.json().getString("path_with_namespace");
}
+ /**
+ * {@inheritDoc}
+ *
+ * Gitlab doc: link
+ */
@Override
public Issues enableIssues() {
- throw new UnsupportedOperationException("Not yet implemented.");
+ final Resource response = this.resources().put(
+ this.repoUri(),
+ Json.createObjectBuilder()
+ .add("issues_access_level", "enabled")
+ .build()
+ );
+ if(response.statusCode() == HttpURLConnection.HTTP_OK) {
+ return this.issues();
+ } else {
+ throw new IllegalStateException(
+ "Could not enable Issues for Repo ["
+ + this.repoUri() + "]. Received Status is "
+ + response.statusCode() + ", while Status 200 OK"
+ + " was expected."
+ );
+ }
}
@Override
diff --git a/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java b/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java
index fa4ba656..68d3601c 100644
--- a/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java
+++ b/self-core-impl/src/test/java/com/selfxdsd/core/GitlabRepoTestCase.java
@@ -11,6 +11,7 @@
import org.mockito.Mockito;
import javax.json.Json;
+import javax.json.JsonValue;
import java.math.BigDecimal;
import java.net.URI;
@@ -238,4 +239,67 @@ public void returnsCommits() {
)
);
}
+
+ /**
+ * GitlabRepo can enable issues.
+ */
+ @Test
+ public void canEnableIssues(){
+ final MockJsonResources res = new MockJsonResources(
+ request -> new MockJsonResources.MockResource(
+ 200,
+ Json.createObjectBuilder().build()
+ )
+ );
+ final Repo repo = new GitlabRepo(
+ res,
+ URI.create("https://gitlab.com/api/v4/projects/1"),
+ Mockito.mock(User.class),
+ Mockito.mock(Storage.class)
+ );
+
+ MatcherAssert.assertThat(
+ repo.enableIssues(),
+ Matchers.instanceOf(Issues.class)
+ );
+
+ final MockJsonResources.MockRequest request = res.requests().first();
+ MatcherAssert.assertThat(
+ request.getUri(),
+ Matchers.equalTo(URI.create("https://gitlab.com/api/v4/projects/1"))
+ );
+ MatcherAssert.assertThat(
+ request.getMethod(),
+ Matchers.equalTo("PUT")
+ );
+ MatcherAssert.assertThat(
+ request.getBody(),
+ Matchers.equalTo(
+ Json.createObjectBuilder()
+ .add("issues_access_level", "enabled")
+ .build()
+ )
+ );
+ }
+
+ /**
+ * GitlabRepo throws IllegalStateException if enableIssues returns status
+ * != 200 OK.
+ */
+ @Test(expected = IllegalStateException.class)
+ public void throwsIllegalStateExceptionIfEnableIssueNotOk() {
+ final JsonResources res = new MockJsonResources(
+ request -> new MockJsonResources.MockResource(
+ 410,
+ JsonValue.EMPTY_JSON_OBJECT
+ )
+ );
+ final Repo repo = new GitlabRepo(
+ res,
+ URI.create("https://gitlab.com/api/v4/projects/1"),
+ Mockito.mock(User.class),
+ Mockito.mock(Storage.class)
+ );
+ repo.enableIssues();
+ }
}