in commit-status-publisher-server/src/main/java/jetbrains/buildServer/commitPublisher/github/api/impl/GitHubApiImpl.java [150:208]
public CombinedCommitStatus readChangeCombinedStatus(@NotNull final String repoOwner,
@NotNull final String repoName,
@NotNull final String hash,
@Nullable final Integer perPage,
@Nullable final Integer page) throws IOException, PublisherException {
final String statusUrl = myUrls.getCombinedStatusUrl(repoOwner, repoName, hash, perPage, page);
final HttpMethod method = HttpMethod.GET;
LoggerUtil.logRequest(Constants.GITHUB_PUBLISHER_ID, method, statusUrl, null);
final AtomicReference<CombinedCommitStatus> status = new AtomicReference<>();
final AtomicReference<Exception> exceptionRef = new AtomicReference<>();
IOGuard.allowNetworkCall(() -> {
myClient.get(statusUrl, authenticationCredentials(), defaultHeaders(),
success -> {
String json = success.getBodyAsString();
if (StringUtil.isEmptyOrSpaces(json)) {
logFailedResponse(HttpMethod.GET, statusUrl, null, success);
exceptionRef.set(new IOException(getErrorMessage(success, "Empty response.")));
return;
}
CombinedCommitStatus combinedCommitStatus;
try {
combinedCommitStatus = myGson.fromJson(json, CombinedCommitStatus.class);
} catch (JsonSyntaxException e) {
exceptionRef.set(new PublisherException("GitHub publisher can not parse malformed json", e));
return;
}
if (null == combinedCommitStatus) {
exceptionRef.set(new PublisherException("GitHub publisher fails to parse a response"));
} else {
status.set(combinedCommitStatus);
}
},
response -> {
String responseBody = logFailedResponse(method, statusUrl, null, response);
String additionalErrorsMessage = parseErrorsFromResponse(responseBody);
PublisherException ex = new PublisherException(getErrorMessage(response, additionalErrorsMessage));
if (RetryResponseProcessor.shouldRetryOnCode(response.getStatusCode())) {
ex.setShouldRetry();
}
exceptionRef.set(ex);
},
e -> exceptionRef.set(e));
});
final Exception ex;
if ((ex = exceptionRef.get()) != null) {
if (ex instanceof PublisherException) {
throw (PublisherException)ex;
} else {
PublisherException e = new PublisherException(ex.getMessage(), ex);
RetryResponseProcessor.processNetworkException(ex, e);
throw e;
}
}
return status.get();
}