Skip to content

Commit 6c81545

Browse files
[NO-JIRA] Log Github errors in case failure on fetching scanner version
1 parent a3b3493 commit 6c81545

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

its/src/test/java/com/sonar/it/jenkins/utility/InstallableScannerVersionsProvider.java

+16-8
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,23 @@
3030

3131
public class InstallableScannerVersionsProvider {
3232
private final OkHttpClient client = new OkHttpClient().newBuilder()
33-
.connectTimeout(10, TimeUnit.SECONDS)
34-
.readTimeout(30, TimeUnit.SECONDS)
35-
.build();
33+
.connectTimeout(10, TimeUnit.SECONDS)
34+
.readTimeout(30, TimeUnit.SECONDS)
35+
.build();
3636

3737
public InstallableScannerVersions getScannerInstallableVersions(String scannerNameRepo) {
3838
JSONArray versions;
39-
try {
40-
HttpUrl.Builder httpBuilder = HttpUrl.parse(String.format("https://api.github.com/repos/SonarSource/%s/releases", scannerNameRepo)).newBuilder();
41-
Request request = new Request.Builder().url(httpBuilder.build()).build();
42-
Response response = client.newCall(request).execute();
43-
versions = new JSONArray(response.body().string());
39+
HttpUrl.Builder httpBuilder = HttpUrl.parse(String.format("https://api.github.com/repos/SonarSource/%s/releases", scannerNameRepo)).newBuilder();
40+
Request request = new Request.Builder().url(httpBuilder.build()).build();
41+
try (Response response = client.newCall(request).execute()) {
42+
43+
if (response.isSuccessful()) {
44+
versions = new JSONArray(response.body().string());
45+
} else {
46+
throw new IllegalStateException(String.format("Got error from Github, status: %d, body: %s",
47+
response.code(), response.body().string()));
48+
}
49+
4450
} catch (IOException | JSONException e) {
4551
throw new IllegalStateException(String.format("Could not fetch earliest supported version of %s", scannerNameRepo), e);
4652
}
@@ -58,9 +64,11 @@ public InstallableScannerVersions(String oldestVersion, String latestVersion) {
5864
this.oldestVersion = oldestVersion;
5965
this.latestVersion = latestVersion;
6066
}
67+
6168
public String getOldestVersion() {
6269
return oldestVersion;
6370
}
71+
6472
public String getLatestVersion() {
6573
return latestVersion;
6674
}

0 commit comments

Comments
 (0)