mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
Add method for getting repo archive link
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Octokit.Internal;
|
||||||
|
|
||||||
namespace Octokit
|
namespace Octokit
|
||||||
{
|
{
|
||||||
@@ -46,6 +47,32 @@ namespace Octokit
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<string> GetReadmeHtml(string owner, string name);
|
Task<string> GetReadmeHtml(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
|
||||||
|
/// Location header to make a second GET request.
|
||||||
|
/// Note: For private repositories, these links are temporary and expire quickly.
|
||||||
|
/// </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<string> GetArchiveLink(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
|
||||||
|
/// Location header to make a second GET request.
|
||||||
|
/// Note: For private repositories, these links are temporary and expire quickly.
|
||||||
|
/// </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<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a commit that creates a new file in a repository.
|
/// Creates a commit that creates a new file in a repository.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -75,4 +102,14 @@ namespace Octokit
|
|||||||
/// <param name="request">Information about the file to delete</param>
|
/// <param name="request">Information about the file to delete</param>
|
||||||
Task DeleteFile(string owner, string name, string path, DeleteFileRequest request);
|
Task DeleteFile(string owner, string name, string path, DeleteFileRequest request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum ArchiveFormat
|
||||||
|
{
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Tarball")]
|
||||||
|
[Parameter(Value = "tarball")]
|
||||||
|
Tarball,
|
||||||
|
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Zipball")]
|
||||||
|
[Parameter(Value = "zipball")]
|
||||||
|
Zipball
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -74,6 +74,42 @@ namespace Octokit
|
|||||||
return ApiConnection.GetHtml(ApiUrls.RepositoryReadme(owner, name), null);
|
return ApiConnection.GetHtml(ApiUrls.RepositoryReadme(owner, name), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <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
|
||||||
|
/// Location header to make a second GET request.
|
||||||
|
/// Note: For private repositories, these links are temporary and expire quickly.
|
||||||
|
/// </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<string> GetArchiveLink(string owner, string name)
|
||||||
|
{
|
||||||
|
return GetArchiveLink(owner, name, ArchiveFormat.Tarball, "master");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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
|
||||||
|
/// Location header to make a second GET request.
|
||||||
|
/// Note: For private repositories, these links are temporary and expire quickly.
|
||||||
|
/// </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 Task<string> GetArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||||
|
|
||||||
|
return ApiConnection.GetRedirect(ApiUrls.RepositoryArchiveLink(owner, name, archiveFormat, reference));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a commit that creates a new file in a repository.
|
/// Creates a commit that creates a new file in a repository.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1467,5 +1467,10 @@ namespace Octokit
|
|||||||
{
|
{
|
||||||
return "repos/{0}/{1}/contents/{2}".FormatUri(owner, name, path);
|
return "repos/{0}/{1}/contents/{2}".FormatUri(owner, name, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Uri RepositoryArchiveLink(string owner, string name, ArchiveFormat archiveFormat, string reference)
|
||||||
|
{
|
||||||
|
return "repos/{0}/{1}/{2}/{3}".FormatUri(owner, name, archiveFormat.ToParameter(), reference);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -386,6 +386,20 @@ namespace Octokit
|
|||||||
return Connection.Delete(uri, data);
|
return Connection.Delete(uri, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<string> GetRedirect(Uri uri)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNull(uri, "uri");
|
||||||
|
var response = await Connection.GetResponse<string>(uri);
|
||||||
|
|
||||||
|
if (response.HttpResponse.StatusCode == HttpStatusCode.Redirect)
|
||||||
|
{
|
||||||
|
return response.HttpResponse.Headers["Location"];
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new ApiException("Redirect Operation expect status code or Redirect.",
|
||||||
|
response.HttpResponse.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes a GET to the API object at the specified URI. This operation is appropriate for
|
/// Executes a GET to the API object at the specified URI. This operation is appropriate for
|
||||||
/// API calls which queue long running calculations.
|
/// API calls which queue long running calculations.
|
||||||
|
|||||||
@@ -232,6 +232,8 @@ namespace Octokit
|
|||||||
/// <returns>A <see cref="Task"/> for the request's execution.</returns>
|
/// <returns>A <see cref="Task"/> for the request's execution.</returns>
|
||||||
Task Delete(Uri uri, object data);
|
Task Delete(Uri uri, object data);
|
||||||
|
|
||||||
|
Task<string> GetRedirect(Uri uri);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes a GET to the API object at the specified URI. This operation is appropriate for
|
/// Executes a GET to the API object at the specified URI. This operation is appropriate for
|
||||||
/// API calls which queue long running calculations.
|
/// API calls which queue long running calculations.
|
||||||
|
|||||||
Reference in New Issue
Block a user