From: Aurelien Poscia Date: Wed, 21 Sep 2022 08:55:37 +0000 (+0200) Subject: SONAR-17340 Add warning in logs in case code scanning alert is available on GitHub... X-Git-Tag: 9.7.0.61563~182 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2a7d745ef17db3e471d5b7935677c9010a24a6a4;p=sonarqube.git SONAR-17340 Add warning in logs in case code scanning alert is available on GitHub but GitHub apps misses permission --- 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