aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Poscia <aurelien.poscia@sonarsource.com>2022-08-24 17:46:58 +0200
committersonartech <sonartech@sonarsource.com>2022-08-30 20:03:14 +0000
commit914890e41cb7131886143a74acd8c4e5f27ec97a (patch)
treefacacb7cb950bb63cc9a29366fb750700aeec2f4
parentf6f59ecbf8e15e3b251bb0a44a0846b5acca7ea4 (diff)
downloadsonarqube-914890e41cb7131886143a74acd8c4e5f27ec97a.tar.gz
sonarqube-914890e41cb7131886143a74acd8c4e5f27ec97a.zip
SONAR-17210 - upload scanning alerts to GitHub
-rw-r--r--server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java3
-rw-r--r--server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java14
2 files changed, 5 insertions, 12 deletions
diff --git a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
index c0a43d6c57f..a716055aee1 100644
--- a/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
+++ b/server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
@@ -40,6 +40,7 @@ import org.sonar.api.utils.log.Loggers;
import org.sonarqube.ws.client.OkHttpClientBuilder;
import static com.google.common.base.Preconditions.checkArgument;
+import static java.net.HttpURLConnection.HTTP_ACCEPTED;
import static java.net.HttpURLConnection.HTTP_CREATED;
import static java.net.HttpURLConnection.HTTP_NO_CONTENT;
import static java.net.HttpURLConnection.HTTP_OK;
@@ -128,7 +129,7 @@ public class GithubApplicationHttpClientImpl implements GithubApplicationHttpCli
try (okhttp3.Response response = client.newCall(newPostRequest(appUrl, token, endPoint, body)).execute()) {
int responseCode = response.code();
- if (responseCode == HTTP_OK || responseCode == HTTP_CREATED) {
+ if (responseCode == HTTP_OK || responseCode == HTTP_CREATED || responseCode == HTTP_ACCEPTED) {
return new ResponseImpl(responseCode, readContent(response.body()).orElse(null));
} else if (responseCode == HTTP_NO_CONTENT) {
return new ResponseImpl(responseCode, null);
diff --git a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java
index 0552666bba9..64ceedb1212 100644
--- a/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java
+++ b/server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java
@@ -235,17 +235,9 @@ public class GithubApplicationHttpClientImplTest {
}
@Test
- public void post_returns_body_as_response_if_code_is_200() throws IOException {
- server.enqueue(new MockResponse().setResponseCode(200).setBody(randomBody));
-
- Response response = underTest.post(appUrl, accessToken, randomEndPoint);
-
- assertThat(response.getContent()).contains(randomBody);
- }
-
- @Test
- public void post_returns_body_as_response_if_code_is_201() throws IOException {
- server.enqueue(new MockResponse().setResponseCode(201).setBody(randomBody));
+ @DataProvider({"200", "201", "202"})
+ public void post_returns_body_as_response_if_success(int code) throws IOException {
+ server.enqueue(new MockResponse().setResponseCode(code).setBody(randomBody));
Response response = underTest.post(appUrl, accessToken, randomEndPoint);