diff --git a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs index 4f1456b9..520bf118 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoryContentsClient.cs @@ -122,6 +122,16 @@ namespace Octokit.Reactive /// IObservable GetAllContents(string owner, string name, string path); + /// + /// Returns the contents of the root directory in a repository. + /// + /// The owner of the repository + /// The name of the repository + /// + /// A collection of representing the content at the specified path + /// + IObservable GetAllContents(string owner, string name); + /// /// Returns the contents of a file or directory in a repository. /// @@ -136,7 +146,19 @@ namespace Octokit.Reactive /// /// A collection of representing the content at the specified path /// - IObservable GetAllContents(string owner, string name, string path, string reference); + IObservable GetAllContentsByRef(string owner, string name, string path, string reference); + + + /// + /// Returns the contents of the home directory in a repository. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + IObservable GetAllContentsByRef(string owner, string name, string reference); /// /// Creates a commit that creates a new file in a repository. diff --git a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs index e4bd9cea..b9f00995 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoryContentsClient.cs @@ -184,6 +184,24 @@ namespace Octokit.Reactive return _client.Repository.Content.GetArchive(owner, name, archiveFormat, reference, timeout).ToObservable(); } + /// + /// Returns the contents of the root directory in a repository. + /// + /// The owner of the repository + /// The name of the repository + /// + /// A collection of representing the content at the specified path + /// + public IObservable GetAllContents(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client + .Connection + .GetAndFlattenAllPages(ApiUrls.RepositoryContent(owner, name, string.Empty)); + } + /// /// Returns the contents of a file or directory in a repository. /// @@ -198,7 +216,7 @@ namespace Octokit.Reactive /// /// A collection of representing the content at the specified path /// - public IObservable GetAllContents(string owner, string name, string path, string reference) + public IObservable GetAllContentsByRef(string owner, string name, string path, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); @@ -208,6 +226,25 @@ namespace Octokit.Reactive return _client.Connection.GetAndFlattenAllPages(ApiUrls.RepositoryContent(owner, name, path, reference)); } + /// + /// Returns the contents of the home directory in a repository. + /// + /// The owner of the repository + /// The name of the repository + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + public IObservable GetAllContentsByRef(string owner, string name, string reference) + { + + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + + return _client.Connection.GetAndFlattenAllPages(ApiUrls.RepositoryContent(owner, name, string.Empty, reference)); + } + /// /// Creates a commit that creates a new file in a repository. /// diff --git a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs index 61b81fd3..46324cbe 100644 --- a/Octokit.Tests/Clients/RepositoryContentsClientTests.cs +++ b/Octokit.Tests/Clients/RepositoryContentsClientTests.cs @@ -58,6 +58,22 @@ namespace Octokit.Tests.Clients public class TheGetContentsMethod { + [Fact] + public async Task ReturnsContentsByRef() + { + List result = new List() { new RepositoryContent() { } }; + + var connection = Substitute.For(); + connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); + var contentsClient = new RepositoryContentsClient(connection); + + var contents = await contentsClient.GetAllContentsByRef("fake", "repo", "readme.md", "master"); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master")); + Assert.Equal(1, contents.Count); + } + + [Fact] public async Task ReturnsContents() { @@ -67,9 +83,9 @@ namespace Octokit.Tests.Clients connection.GetAll(Args.Uri).Returns(Task.FromResult(result.AsReadOnly() as IReadOnlyList)); var contentsClient = new RepositoryContentsClient(connection); - var contents = await contentsClient.GetAllContents("fake", "repo", "readme.md", "master"); + var contents = await contentsClient.GetAllContents("fake", "repo", "readme.md"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/contents/readme.md")); Assert.Equal(1, contents.Count); } } diff --git a/Octokit/Clients/IRepositoryContentsClient.cs b/Octokit/Clients/IRepositoryContentsClient.cs index 2fce3365..dc28614b 100644 --- a/Octokit/Clients/IRepositoryContentsClient.cs +++ b/Octokit/Clients/IRepositoryContentsClient.cs @@ -25,6 +25,18 @@ namespace Octokit /// Task> GetAllContents(string owner, string name, string path); + + /// + /// Returns the contents of the root directory in a repository. + /// + /// + /// The owner of the repository + /// The name of the repository + /// + /// A collection of representing the content at the specified path + /// + Task> GetAllContents(string owner, string name); + /// /// Returns the contents of a file or directory in a repository. /// @@ -39,7 +51,19 @@ namespace Octokit /// /// A collection of representing the content at the specified path /// - Task> GetAllContents(string owner, string name, string path, string reference); + Task> GetAllContentsByRef(string owner, string name, string path, string reference); + + /// + /// Returns the contents of the root directory in a repository. + /// + /// + /// The owner of the repository + /// The name of the repository + /// The name of the commit/branch/tag. Default: the repository’s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + Task> GetAllContentsByRef(string owner, string name,string reference); /// /// Gets the preferred README for the specified repository. diff --git a/Octokit/Clients/RepositoryContentsClient.cs b/Octokit/Clients/RepositoryContentsClient.cs index 859424cb..008151cf 100644 --- a/Octokit/Clients/RepositoryContentsClient.cs +++ b/Octokit/Clients/RepositoryContentsClient.cs @@ -40,6 +40,26 @@ namespace Octokit return await ApiConnection.GetAll(url); } + /// + /// Returns the contents of the root directory in a repository. + /// + /// + /// The owner of the repository + /// The name of the repository + /// + /// A collection of representing the content at the specified path + /// + public async Task> GetAllContents(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + var url = ApiUrls.RepositoryContent(owner, name, string.Empty); + + return await ApiConnection.GetAll(url); + } + + /// /// Returns the contents of a file or directory in a repository. /// @@ -54,15 +74,38 @@ namespace Octokit /// /// A collection of representing the content at the specified path /// - public async Task> GetAllContents(string owner, string name, string path, string reference) + public async Task> GetAllContentsByRef(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(url); + } + /// + /// Returns the contents of the root directory in a repository. + /// + /// + /// The owner of the repository + /// The name of the repository + /// The name of the commit/branch/tag. Default: the repository�s default branch (usually master) + /// + /// A collection of representing the content at the specified path + /// + public async Task> GetAllContentsByRef(string owner, string name, string reference) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); - Ensure.ArgumentNotNullOrEmptyString(reference, "reference"); + Ensure.ArgumentNotNullOrEmptyString(name, "reference"); - var url = ApiUrls.RepositoryContent(owner, name, path, reference); + var url = ApiUrls.RepositoryContent(owner, name,string.Empty,reference); return await ApiConnection.GetAll(url); + } ///