Commit 1c4df098 authored by Tyler Rockwood's avatar Tyler Rockwood

Added getBuildArtifact method

I ran into an odd issue where the download files were 10MB too big
and were in an invalid .tgz format, but reading the byte stream
from the actual input stream instead of the reader fixed the issue.
parent 68489e45
......@@ -612,6 +612,29 @@ public class GitlabAPI {
}
/**
* Get build artifacts of a project build
*
* @param project The Project
* @param build The build
* @throws IOException on gitlab api call error
*/
public byte[] getBuildArtifact(GitlabProject project, GitlabBuild build) throws IOException {
return getBuildArtifact(project.getId(), build.getId());
}
/**
* Get build artifacts of a project build
*
* @param projectId The Project's Id
* @param buildId The build's Id
* @throws IOException on gitlab api call error
*/
public byte[] getBuildArtifact(Integer projectId, Integer buildId) throws IOException {
String tailUrl = GitlabProject.URL + "/" + sanitizeProjectId(projectId) + GitlabBuild.URL + "/" + buildId + "/artifacts";
return retrieve().to(tailUrl, byte[].class);
}
/**
* Creates a private Project
*
......
......@@ -321,10 +321,10 @@ public class GitlabHTTPRequestor {
private <T> T parse(HttpURLConnection connection, Class<T> type, T instance) throws IOException {
InputStreamReader reader = null;
try {
reader = new InputStreamReader(wrapStream(connection, connection.getInputStream()), "UTF-8");
if (byte[].class == type) {
return type.cast(IOUtils.toByteArray(reader));
return type.cast(IOUtils.toByteArray(connection.getInputStream()));
}
reader = new InputStreamReader(wrapStream(connection, connection.getInputStream()), "UTF-8");
String data = IOUtils.toString(reader);
if (type != null) {
return GitlabAPI.MAPPER.readValue(data, type);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment