Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finish support for downloading the code archive #810

Merged
merged 5 commits into from
Jun 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,18 @@ public interface IObservableRepositoryContentsClient
/// <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>
/// <returns>A promise, containing the binary contents of the archive</returns>
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
Expand All @@ -47,8 +57,19 @@ public interface IObservableRepositoryContentsClient
/// <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>A promise, containing the binary contents of the archive</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
Expand All @@ -61,8 +82,20 @@ public interface IObservableRepositoryContentsClient
/// <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>
/// <returns>A promise, containing the binary contents of the archive</returns>
IObservable<byte[]> GetArchive(string owner, string name, ArchiveFormat archiveFormat, string reference);

/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
Expand Down
42 changes: 42 additions & 0 deletions Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,24 @@ public IObservable<string> GetReadmeHtml(string owner, string name)
/// <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>
/// <returns>A promise, containing the binary contents of the archive</returns>
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
Expand All @@ -75,11 +88,25 @@ public IObservable<string> GetArchiveLink(string owner, string name)
/// <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>A promise, containing the binary contents of the archive</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
Expand All @@ -92,6 +119,7 @@ public IObservable<string> GetArchiveLink(string owner, string name, ArchiveForm
/// <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");
Expand All @@ -100,6 +128,20 @@ public IObservable<string> GetArchiveLink(string owner, string name, ArchiveForm
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>
/// <returns>A promise, containing the binary contents of the archive</returns>
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>
Expand Down
26 changes: 13 additions & 13 deletions Octokit.Tests.Integration/Clients/RepositoryContentsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,43 +115,43 @@ await Assert.ThrowsAsync<NotFoundException>(
}
}

[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);
}
}
}
13 changes: 0 additions & 13 deletions Octokit.Tests/Http/RedirectHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@ public async Task RedirectWithDifferentHostShouldLoseAuthHeader(HttpStatusCode s
Assert.Null(response.RequestMessage.Headers.Authorization);

}

[Fact]
public async Task DisabledRedirectShouldPassThrough()
{
var invoker = CreateInvoker(new HttpResponseMessage(HttpStatusCode.Found));
var httpRequestMessage = CreateRequest(HttpMethod.Get);
httpRequestMessage.Properties[RedirectHandler.AllowAutoRedirectKey] = false;
var response = await invoker.SendAsync(httpRequestMessage, new CancellationToken());

Assert.Equal(response.StatusCode, HttpStatusCode.Redirect);
Assert.Same(response.RequestMessage, httpRequestMessage);
}

[Theory]
[InlineData(HttpStatusCode.MovedPermanently)] // 301
Expand Down Expand Up @@ -179,7 +167,6 @@ static HttpRequestMessage CreateRequest(HttpMethod method)
{
var httpRequestMessage = new HttpRequestMessage();
httpRequestMessage.RequestUri = new Uri("http://example.org/foo");
httpRequestMessage.Properties[RedirectHandler.AllowAutoRedirectKey] = true;
httpRequestMessage.Method = method;
return httpRequestMessage;
}
Expand Down
34 changes: 34 additions & 0 deletions Octokit/Clients/IRepositoryContentsClient.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Octokit.Internal;
Expand Down Expand Up @@ -57,8 +58,18 @@ public interface IRepositoryContentsClient
/// <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>The binary contents of the archive</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
Expand All @@ -70,8 +81,19 @@ public interface IRepositoryContentsClient
/// <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>The binary contents of the archive</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
Expand All @@ -84,8 +106,20 @@ public interface IRepositoryContentsClient
/// <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>The binary contents of the archive</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>
Expand Down
46 changes: 46 additions & 0 deletions Octokit/Clients/RepositoryContentsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ public Task<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>
/// <returns>The binary contents of the archive</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
Expand All @@ -105,6 +117,19 @@ public Task<string> GetArchiveLink(string owner, string name, ArchiveFormat arch
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>The binary contents of the archive</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
Expand All @@ -125,6 +150,27 @@ public Task<string> GetArchiveLink(string owner, string name, ArchiveFormat arch
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>The binary contents of the archive</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>
Expand Down
Loading