Skip to content

Commit

Permalink
#1254 GitlabRepo enable issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
criske committed Oct 22, 2021
1 parent b65580b commit 4f9e654
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 81 deletions.
66 changes: 0 additions & 66 deletions self-core-impl/src/main/java/com/selfxdsd/core/EmptyIssues.java

This file was deleted.

34 changes: 23 additions & 11 deletions self-core-impl/src/main/java/com/selfxdsd/core/GitlabRepo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import com.selfxdsd.api.*;
import com.selfxdsd.api.Labels;
import com.selfxdsd.api.storage.Storage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.json.Json;
import javax.json.JsonObject;
import java.net.HttpURLConnection;
import java.net.URI;

/**
Expand All @@ -39,13 +39,6 @@
*/
final class GitlabRepo extends BaseRepo {

/**
* Logger.
*/
private static final Logger LOG = LoggerFactory.getLogger(
GitlabRepo.class
);

/**
* Constructor.
* @param resources Gitlab's JSON Resources.
Expand Down Expand Up @@ -155,10 +148,29 @@ public String fullName() {
return this.json().getString("path_with_namespace");
}

/**
* {@inheritDoc}
* <br/>
* Gitlab doc: <a href="https://docs.gitlab.com/ee/api/projects.html#edit-project">link</a>
*/
@Override
public Issues enableIssues() {
LOG.warn("Gitlab doesn't support enabling issues...");
return new EmptyIssues();
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.mockito.Mockito;

import javax.json.Json;
import javax.json.JsonValue;
import java.math.BigDecimal;
import java.net.URI;

Expand Down Expand Up @@ -240,19 +241,65 @@ public void returnsCommits() {
}

/**
* Gitlab doesn't support enabling issues.
* GitlabRepo can enable issues.
*/
@Test
public void doesNotSupportEnableIssues(){
public void canEnableIssues(){
final MockJsonResources res = new MockJsonResources(
request -> new MockJsonResources.MockResource(
200,
Json.createObjectBuilder().build()
)
);
final Repo repo = new GitlabRepo(
Mockito.mock(JsonResources.class),
res,
URI.create("https://gitlab.com/api/v4/projects/1"),
Mockito.mock(User.class),
Mockito.mock(Storage.class)
);

MatcherAssert.assertThat(
repo.enableIssues(),
Matchers.instanceOf(EmptyIssues.class)
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();
}
}

0 comments on commit 4f9e654

Please sign in to comment.