(fix) RepositoryContentsClient.GetArchive does not return the expected binary content (#2803)

* (GH-2802) Add unit test to demonstrate the problem

This unit test currently fails which demonstrates the problem and it should pass when I am done with the PR

* (GH-2802) Add a GetRaw method that accepts a timeout

I debated adding an optional parameter for the timeout to the existing GetRaw method (which would be my personal preference) but it would be a breaking change and I doubt the Octokit team would be interested in such a change

* (GH-2802) Invoke `GetRaw` rather than `Get>byte[]>` when retrieving a repo's archive content.

This ensure stream content are handled properly and solves the problem described in GitHub issue 2802

* (GH-2802) Fix unit tests that got broken due to my recent change to the GetArchive method

* (GH-2802) Fix formatting

* (GH-2802) Fix more formatting
This commit is contained in:
Jericho
2023-10-16 13:38:12 -04:00
committed by GitHub
parent 7b3abda711
commit 1eac8315ff
4 changed files with 59 additions and 12 deletions

View File

@@ -395,7 +395,7 @@ namespace Octokit
var endpoint = ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference);
var response = await Connection.Get<byte[]>(endpoint, timeout).ConfigureAwait(false);
var response = await Connection.GetRaw(endpoint, null, timeout).ConfigureAwait(false);
return response.Body;
}
@@ -416,7 +416,7 @@ namespace Octokit
var endpoint = ApiUrls.RepositoryArchiveLink(repositoryId, archiveFormat, reference);
var response = await Connection.Get<byte[]>(endpoint, timeout).ConfigureAwait(false);
var response = await Connection.GetRaw(endpoint, null, timeout).ConfigureAwait(false);
return response.Body;
}

View File

@@ -242,7 +242,21 @@ namespace Octokit
Endpoint = uri.ApplyParameters(parameters)
});
}
/// <inheritdoc/>
public Task<IApiResponse<byte[]>> GetRaw(Uri uri, IDictionary<string, string> parameters, TimeSpan timeout)
{
Ensure.ArgumentNotNull(uri, nameof(uri));
return GetRaw(new Request
{
Method = HttpMethod.Get,
BaseAddress = BaseAddress,
Endpoint = uri.ApplyParameters(parameters),
Timeout = timeout
});
}
/// <inheritdoc/>
public Task<IApiResponse<Stream>> GetRawStream(Uri uri, IDictionary<string, string> parameters)
{

View File

@@ -30,7 +30,17 @@ namespace Octokit
/// <returns><seealso cref="IResponse"/> representing the received HTTP response</returns>
/// <remarks>The <see cref="IResponse.Body"/> property will be <c>null</c> if the <paramref name="uri"/> points to a directory instead of a file</remarks>
Task<IApiResponse<byte[]>> GetRaw(Uri uri, IDictionary<string, string> parameters);
/// <summary>
/// Performs an asynchronous HTTP GET request that expects a <seealso cref="IResponse"/> containing raw data.
/// </summary>
/// <param name="uri">URI endpoint to send request to</param>
/// <param name="parameters">Querystring parameters for the request</param>
/// <param name="timeout">The Timeout value</param>
/// <returns><seealso cref="IResponse"/> representing the received HTTP response</returns>
/// <remarks>The <see cref="IResponse.Body"/> property will be <c>null</c> if the <paramref name="uri"/> points to a directory instead of a file</remarks>
Task<IApiResponse<byte[]>> GetRaw(Uri uri, IDictionary<string, string> parameters, TimeSpan timeout);
/// <summary>
/// Performs an asynchronous HTTP GET request that expects a <seealso cref="IResponse"/> containing raw data.
/// </summary>