mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 11:40:42 +00:00
Merge pull request #730 from goalie7960/get-contents-api
added support for ref value in get contents api
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reactive;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
@@ -110,6 +111,22 @@ namespace Octokit.Reactive
|
||||
/// </returns>
|
||||
IObservable<RepositoryContent> GetAllContents(string owner, string name, string path);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the contents of a file or directory in a repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If given a path to a single file, this method returns a collection containing only that file.
|
||||
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="path">The content path</param>
|
||||
/// <param name="reference">The name of the commit/branch/tag. Default: the repository’s default branch (usually master)</param>
|
||||
/// <returns>
|
||||
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
|
||||
/// </returns>
|
||||
IObservable<RepositoryContent> GetAllContents(string owner, string name, string path, string reference);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a commit that creates a new file in a repository.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Internal;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
@@ -165,6 +166,30 @@ namespace Octokit.Reactive
|
||||
.GetAndFlattenAllPages<RepositoryContent>(ApiUrls.RepositoryContent(owner, name, path));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the contents of a file or directory in a repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If given a path to a single file, this method returns a collection containing only that file.
|
||||
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="path">The content path</param>
|
||||
/// <param name="reference">The name of the commit/branch/tag. Default: the repository’s default branch (usually master)</param>
|
||||
/// <returns>
|
||||
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
|
||||
/// </returns>
|
||||
public IObservable<RepositoryContent> GetAllContents(string owner, string name, string path, string reference)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(path, "path");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||
|
||||
return _client.Connection.GetAndFlattenAllPages<RepositoryContent>(ApiUrls.RepositoryContent(owner, name, path, reference));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a commit that creates a new file in a repository.
|
||||
/// </summary>
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
@@ -108,5 +109,23 @@ namespace Octokit.Tests.Clients
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => contentsClient.GetArchiveLink("owner", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetContentsMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task ReturnsContents()
|
||||
{
|
||||
List<RepositoryContent> result = new List<RepositoryContent>() { new RepositoryContent() { } };
|
||||
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
connection.GetAll<RepositoryContent>(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList<RepositoryContent>));
|
||||
var contentsClient = new RepositoryContentsClient(connection);
|
||||
|
||||
var contents = await contentsClient.GetAllContents("fake", "repo", "readme.md", "master");
|
||||
|
||||
connection.Received().GetAll<RepositoryContent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master"));
|
||||
Assert.Equal(1, contents.Count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ namespace Octokit
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If given a path to a single file, this method returns a collection containing only that file.
|
||||
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
@@ -24,6 +25,22 @@ namespace Octokit
|
||||
/// </returns>
|
||||
Task<IReadOnlyList<RepositoryContent>> GetAllContents(string owner, string name, string path);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the contents of a file or directory in a repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If given a path to a single file, this method returns a collection containing only that file.
|
||||
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="path">The content path</param>
|
||||
/// <param name="reference">The name of the commit/branch/tag. Default: the repository’s default branch (usually master)</param>
|
||||
/// <returns>
|
||||
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
|
||||
/// </returns>
|
||||
Task<IReadOnlyList<RepositoryContent>> GetAllContents(string owner, string name, string path, string reference);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the preferred README for the specified repository.
|
||||
/// </summary>
|
||||
|
||||
@@ -18,6 +18,7 @@ namespace Octokit
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If given a path to a single file, this method returns a collection containing only that file.
|
||||
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
@@ -36,6 +37,32 @@ namespace Octokit
|
||||
return await ApiConnection.GetAll<RepositoryContent>(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the contents of a file or directory in a repository.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// If given a path to a single file, this method returns a collection containing only that file.
|
||||
/// See the <a href="https://developer.github.com/v3/repos/contents/#get-contents">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="path">The content path</param>
|
||||
/// <param name="reference">The name of the commit/branch/tag. Default: the repository�s default branch (usually master)</param>
|
||||
/// <returns>
|
||||
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
|
||||
/// </returns>
|
||||
public async Task<IReadOnlyList<RepositoryContent>> GetAllContents(string owner, string name, string path, string reference)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNullOrEmptyString(path, "path");
|
||||
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
|
||||
|
||||
var url = ApiUrls.RepositoryContent(owner, name, path, reference);
|
||||
|
||||
return await ApiConnection.GetAll<RepositoryContent>(url);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the preferred README for the specified repository.
|
||||
/// </summary>
|
||||
|
||||
@@ -1541,5 +1541,18 @@ namespace Octokit
|
||||
{
|
||||
return "repos/{0}/{1}/{2}/{3}".FormatUri(owner, name, archiveFormat.ToParameter(), reference);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the relative <see cref="Uri"/> for getting the contents of the specified repository and path
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="path">The path of the contents to get</param>
|
||||
/// <param name="reference">The name of the commit/branch/tag. Default: the repository’s default branch (usually master)</param>
|
||||
/// <returns>The <see cref="Uri"/> for getting the contents of the specified repository and path</returns>
|
||||
public static Uri RepositoryContent(string owner, string name, string path, string reference)
|
||||
{
|
||||
return "repos/{0}/{1}/contents/{2}?ref={3}".FormatUri(owner, name, path, reference);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user