diff --git a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java index 4013cd02465..7e6c0a8b902 100644 --- a/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java +++ b/src/test/java/org/arquillian/tests/utilities/GitHubProjectVersionExtractor.java @@ -3,11 +3,21 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; import org.apache.http.client.utils.URIBuilder; import org.jboss.arquillian.drone.webdriver.utils.HttpClient; +import org.jboss.arquillian.drone.webdriver.utils.Validate; + +import static org.jboss.arquillian.drone.webdriver.binary.downloading.source.GitHubSource.AUTHORIZATION_HEADER_KEY; public class GitHubProjectVersionExtractor { + private static final String OAUTH_AUTHORIZATION_HEADER_VALUE_PREFIX = "Bearer "; + private String TAGS_URL = "/tags"; private String TAG_NAME = "name"; private String project; @@ -18,7 +28,7 @@ public GitHubProjectVersionExtractor(String project) { public String getLatestReleaseFromGitHub() { try { - final HttpClient.Response response = sentGetRequestWithPagination(project + TAGS_URL, 1); + final HttpClient.Response response = sentGetRequestWithPagination(project + TAGS_URL, 1, getAuthorizationHeader()); JsonArray releaseTags = new Gson().fromJson(response.getPayload(), JsonElement.class).getAsJsonArray(); if (releaseTags.size() == 0) { return null; @@ -29,11 +39,21 @@ public String getLatestReleaseFromGitHub() { } } - private HttpClient.Response sentGetRequestWithPagination(String url, int pageNumber) throws Exception { + private HttpClient.Response sentGetRequestWithPagination(String url, int pageNumber, Map headers) + throws Exception { final URIBuilder uriBuilder = new URIBuilder(url); if (pageNumber != 1) { uriBuilder.setParameter("page", String.valueOf(pageNumber)); } - return new HttpClient().get(uriBuilder.build().toString()); + return new HttpClient().get(uriBuilder.build().toString(), headers); + } + + private Map getAuthorizationHeader() throws IOException { + Map headers = new HashMap<>(); + String token = new String(Files.readAllBytes(Paths.get(".github-auth"))).trim(); + if (Validate.nonEmpty(token)) { + headers.put(AUTHORIZATION_HEADER_KEY, OAUTH_AUTHORIZATION_HEADER_VALUE_PREFIX + token); + } + return headers; } }