Skip to content
This repository was archived by the owner on Aug 12, 2020. It is now read-only.

Commit b8e3a8c

Browse files
committed
Define a more suitable report key for Bitbucket Server
1 parent cd82373 commit b8e3a8c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/main/java/com/github/goober/sonarqube/plugin/decorator/bitbucket/BitbucketClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
@ComputeEngineSide
2424
public class BitbucketClient {
2525
private static final Logger LOGGER = Loggers.get(BitbucketClient.class);
26-
26+
private static final String REPORT_KEY = "com.github.goober.sonarqube.plugin.decorator";
2727
private final Configuration configuration;
2828

2929
private OkHttpClient client;
@@ -42,7 +42,7 @@ void createReport(String project, String repository, String commit, CreateReport
4242
String body = getObjectMapper().writeValueAsString(request);
4343
Request req = new Request.Builder()
4444
.put(RequestBody.create(body, MediaType.parse("application/json")))
45-
.url(format("%s/rest/insights/1.0/projects/%s/repos/%s/commits/%s/reports/com.foobar", baseUrl(), project, repository, commit))
45+
.url(format("%s/rest/insights/1.0/projects/%s/repos/%s/commits/%s/reports/%s", baseUrl(), project, repository, commit, REPORT_KEY))
4646
.build();
4747

4848
try (Response response = getClient().newCall(req).execute()) {
@@ -51,9 +51,12 @@ void createReport(String project, String repository, String commit, CreateReport
5151
}
5252

5353
void createAnnotations(String project, String repository, String commit, CreateAnnotationsRequest request) throws IOException {
54+
if (request.getAnnotations().isEmpty()) {
55+
return;
56+
}
5457
Request req = new Request.Builder()
5558
.post(RequestBody.create(getObjectMapper().writeValueAsString(request), MediaType.parse("application/json")))
56-
.url(format("%s/rest/insights/1.0/projects/%s/repos/%s/commits/%s/reports/com.foobar/annotations", baseUrl(), project, repository, commit))
59+
.url(format("%s/rest/insights/1.0/projects/%s/repos/%s/commits/%s/reports/%s/annotations", baseUrl(), project, repository, commit, REPORT_KEY))
5760
.build();
5861
try (Response response = getClient().newCall(req).execute()) {
5962
validate(response);
@@ -63,15 +66,15 @@ void createAnnotations(String project, String repository, String commit, CreateA
6366
void deleteAnnotations(String project, String repository, String commit) throws IOException {
6467
Request req = new Request.Builder()
6568
.delete()
66-
.url(format("%s/rest/insights/1.0/projects/%s/repos/%s/commits/%s/reports/com.foobar/annotations", baseUrl(), project, repository, commit))
69+
.url(format("%s/rest/insights/1.0/projects/%s/repos/%s/commits/%s/reports/%s/annotations", baseUrl(), project, repository, commit, REPORT_KEY))
6770
.build();
6871
try (Response response = getClient().newCall(req).execute()) {
6972
validate(response);
7073
}
7174
}
7275

7376
private void validate(Response response) throws IOException {
74-
if(!response.isSuccessful()) {
77+
if (!response.isSuccessful()) {
7578
LOGGER.error("{} - {}", response.code(), response.body() == null ? "" : response.body().string());
7679
throw new IOException(format("Bitbucket responded with an unsuccessful response %d", response.code()));
7780
}

0 commit comments

Comments
 (0)