introduce GetArchive overloads for RepositoryContentClients which handles the redirect

This commit is contained in:
Brendan Forster
2015-06-01 07:48:21 +09:30
parent 3acdd10be4
commit 54e0865e37
5 changed files with 164 additions and 13 deletions
@@ -34,8 +34,17 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
IObservable<string> GetArchiveLink(string owner, string name);
/// <summary>
/// Get an archive of a given repository's contents
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
IObservable<byte[]> GetArchive(string owner, string name);
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -47,8 +56,19 @@ namespace Octokit.Reactive
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
IObservable<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat);
/// <summary>
/// Get an archive of a given repository's contents, in a specific format
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <returns></returns>
IObservable<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat);
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -61,8 +81,19 @@ namespace Octokit.Reactive
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <param name="reference">A valid Git reference.</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
IObservable<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference);
/// <summary>
/// Get an archive of a given repository's contents, using a specific format and reference
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <param name="reference">A valid Git reference.</param>
IObservable<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference);
/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
@@ -59,11 +59,23 @@ namespace Octokit.Reactive
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
public IObservable<string> GetArchiveLink(string owner, string name)
{
return GetArchiveLink(owner, name, ArchiveFormat.Tarball, string.Empty);
}
/// <summary>
/// Get an archive of a given repository's contents
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
public IObservable<byte[]> GetArchive(string owner, string name)
{
return _client.Repository.Content.GetArchive(owner, name).ToObservable();
}
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -75,11 +87,25 @@ namespace Octokit.Reactive
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
public IObservable<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat)
{
return GetArchiveLink(owner, name, archiveFormat, String.Empty);
}
/// <summary>
/// Get an archive of a given repository's contents, in a specific format
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <returns></returns>
public IObservable<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat)
{
return _client.Repository.Content.GetArchive(owner, name, archiveFormat).ToObservable();
}
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -92,6 +118,7 @@ namespace Octokit.Reactive
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <param name="reference">A valid Git reference.</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
public IObservable<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
@@ -100,6 +127,19 @@ namespace Octokit.Reactive
return _client.Repository.Content.GetArchiveLink(owner, name, archiveFormat, reference).ToObservable();
}
/// <summary>
/// Get an archive of a given repository's contents, using a specific format and reference
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <param name="reference">A valid Git reference.</param>
public IObservable<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference)
{
return _client.Repository.Content.GetArchive(owner, name, archiveFormat, reference).ToObservable();
}
/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
@@ -115,43 +115,43 @@ namespace Octokit.Tests.Integration.Clients
}
}
[IntegrationTest]
public async Task GetsArchiveLinkAsTarball()
[IntegrationTest(Skip = "this will probably take too long")]
public async Task GetsArchiveAsTarball()
{
var github = Helper.GetAuthenticatedClient();
var archiveLink = await github
var archive = await github
.Repository
.Content
.GetArchiveLink("octokit", "octokit.net");
.GetArchive("octokit", "octokit.net");
Assert.Equal("https://codeload.github.com/octokit/octokit.net/legacy.tar.gz/master", archiveLink);
Assert.NotEmpty(archive);
}
[IntegrationTest]
public async Task GetsArchiveLinkAsZipball()
public async Task GetsArchiveAsZipball()
{
var github = Helper.GetAuthenticatedClient();
var archiveLink = await github
var archive = await github
.Repository
.Content
.GetArchiveLink("octokit", "octokit.net", ArchiveFormat.Zipball, "");
.GetArchive("octokit", "octokit.net", ArchiveFormat.Zipball, "");
Assert.Equal("https://codeload.github.com/octokit/octokit.net/legacy.zip/master", archiveLink);
Assert.NotEmpty(archive);
}
[IntegrationTest]
public async Task GetsArchiveLinkForReleaseBranchAsTarball()
public async Task GetsArchiveForReleaseBranchAsTarball()
{
var github = Helper.GetAuthenticatedClient();
var archiveLink = await github
var archive = await github
.Repository
.Content
.GetArchiveLink("alfhenrik", "ScriptCs.OctoKit", ArchiveFormat.Tarball, "dev");
.GetArchive("alfhenrik", "ScriptCs.OctoKit", ArchiveFormat.Tarball, "dev");
Assert.Equal("https://codeload.github.com/alfhenrik/ScriptCs.OctoKit/legacy.tar.gz/dev", archiveLink);
Assert.NotEmpty(archive);
}
}
}
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit.Internal;
@@ -57,8 +58,18 @@ namespace Octokit
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
Task<string> GetArchiveLink(string owner, string name);
/// <summary>
/// Get an archive of a given repository's contents
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
Task<byte[]> GetArchive(string owner, string name);
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -70,8 +81,19 @@ namespace Octokit
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
Task<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat);
/// <summary>
/// Get an archive of a given repository's contents, in a specific format
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <returns></returns>
Task<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat);
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -84,8 +106,20 @@ namespace Octokit
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <param name="reference">A valid Git reference.</param>
/// <returns></returns>
[Obsolete("Use GetArchive to download the archive instead")]
Task<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference);
/// <summary>
/// Get an archive of a given repository's contents, using a specific format and reference
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <param name="reference">A valid Git reference.</param>
/// <returns></returns>
Task<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference);
/// <summary>
/// Creates a commit that creates a new file in a repository.
/// </summary>
@@ -89,6 +89,18 @@ namespace Octokit
return GetArchiveLink(owner, name, ArchiveFormat.Tarball, string.Empty);
}
/// <summary>
/// Get an archive of a given repository's contents
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public Task<byte[]> GetArchive(string owner, string name)
{
return GetArchive(owner, name, ArchiveFormat.Tarball, string.Empty);
}
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -105,6 +117,19 @@ namespace Octokit
return GetArchiveLink(owner, name, archiveFormat, string.Empty);
}
/// <summary>
/// Get an archive of a given repository's contents, in a specific format
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <returns></returns>
public Task<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat)
{
return GetArchive(owner, name, archiveFormat, string.Empty);
}
/// <summary>
/// This method will return a 302 to a URL to download a tarball or zipball archive for a repository.
/// Please make sure your HTTP framework is configured to follow redirects or you will need to use the
@@ -125,6 +150,27 @@ namespace Octokit
return ApiConnection.GetRedirect(ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference));
}
/// <summary>
/// Get an archive of a given repository's contents, using a specific format and reference
/// </summary>
/// <remarks>https://developer.github.com/v3/repos/contents/#get-archive-link</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="archiveFormat">The format of the archive. Can be either tarball or zipball</param>
/// <param name="reference">A valid Git reference.</param>
/// <returns></returns>
public async Task<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var endpoint = ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference);
var response = await Connection.Get<byte[]>(endpoint, new Dictionary<string, string>(), null);
return response.Body;
}
/// <summary>
/// Creates a commit that creates a new file in a repository.
/// </summary>