]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17340 Add warning in logs in case code scanning alert is available on GitHub...
authorAurelien Poscia <aurelien.poscia@sonarsource.com>
Wed, 21 Sep 2022 08:55:37 +0000 (10:55 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 22 Sep 2022 20:03:34 +0000 (20:03 +0000)
server/sonar-alm-client/src/main/java/org/sonar/alm/client/github/GithubApplicationHttpClientImpl.java
server/sonar-alm-client/src/test/java/org/sonar/alm/client/github/GithubApplicationHttpClientImplTest.java

index 0572f7ceb326af90cd68d818a46980f75293ce8d..96045882a0b14f25f22628741241bf704dcbdc95 100644 (file)
@@ -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));
     }
index 5287253b83756a7d5c5390286f85a8a48f25cb5f..5b41d67b2e6eb1a5033135680a96560ed2c63a47 100644 (file)
@@ -157,7 +157,7 @@ public class GithubApplicationHttpClientImplTest {
 
     GetResponse response = underTest.get(appUrl, accessToken, randomEndPoint);
 
-    assertThat(response.getContent()).isEmpty();
+    assertThat(response.getContent()).contains(randomBody);
   }
 
   @Test