diff options
author | Aurelien Poscia <aurelien.poscia@sonarsource.com> | 2022-09-21 10:55:37 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-09-22 20:03:34 +0000 |
commit | 2a7d745ef17db3e471d5b7935677c9010a24a6a4 (patch) | |
tree | a37123d77f07e169eaf8dcf7ab01b6d6adb6f6b4 /server/sonar-alm-client | |
parent | 4403555a430bfa814e261a0e680b953bab9d9594 (diff) | |
download | sonarqube-2a7d745ef17db3e471d5b7935677c9010a24a6a4.tar.gz sonarqube-2a7d745ef17db3e471d5b7935677c9010a24a6a4.zip |
SONAR-17340 Add warning in logs in case code scanning alert is available on GitHub but GitHub apps misses permission
Diffstat (limited to 'server/sonar-alm-client')
2 files changed, 5 insertions, 3 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 0572f7ceb32..96045882a0b 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 @@ -33,6 +33,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.ResponseBody; +import org.apache.commons.lang.StringUtils; import org.sonar.alm.client.TimeoutConfiguration; import org.sonar.alm.client.github.security.AccessToken; import org.sonar.api.utils.log.Logger; @@ -82,10 +83,11 @@ public class GithubApplicationHttpClientImpl implements GithubApplicationHttpCli try (okhttp3.Response response = client.newCall(newGetRequest(appUrl, token, endPoint)).execute()) { int responseCode = response.code(); if (responseCode != HTTP_OK) { + String content = StringUtils.trimToNull(attemptReadContent(response)); if (withLog) { - LOG.warn("GET response did not have expected HTTP code (was {}): {}", responseCode, attemptReadContent(response)); + LOG.warn("GET response did not have expected HTTP code (was {}): {}", responseCode, content); } - return new GetResponseImpl(responseCode, null, null); + return new GetResponseImpl(responseCode, content, null); } return new GetResponseImpl(responseCode, readContent(response.body()).orElse(null), readNextEndPoint(response)); } 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 5287253b837..5b41d67b2e6 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 @@ -157,7 +157,7 @@ public class GithubApplicationHttpClientImplTest { GetResponse response = underTest.get(appUrl, accessToken, randomEndPoint); - assertThat(response.getContent()).isEmpty(); + assertThat(response.getContent()).contains(randomBody); } @Test |