New method signatures for the getting contents by ref

Implemented new method signatures for the getting contents by in which
the client need not pass the path. It defaults to the root folder.
This commit is contained in:
Naveen
2015-11-19 21:58:36 -05:00
committed by Brendan Forster
parent fd3fd314a2
commit 9d7a17fdea
5 changed files with 150 additions and 8 deletions
@@ -122,6 +122,16 @@ namespace Octokit.Reactive
/// </returns>
IObservable<RepositoryContent> GetAllContents(string owner, string name, string path);
/// <summary>
/// Returns the contents of the root directory in a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
IObservable<RepositoryContent> GetAllContents(string owner, string name);
/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
@@ -136,7 +146,19 @@ namespace Octokit.Reactive
/// <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);
IObservable<RepositoryContent> GetAllContentsByRef(string owner, string name, string path, string reference);
/// <summary>
/// Returns the contents of the home directory in a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the commit/branch/tag. Default: the repositorys default branch (usually master)</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
IObservable<RepositoryContent> GetAllContentsByRef(string owner, string name, string reference);
/// <summary>
/// Creates a commit that creates a new file in a repository.
@@ -184,6 +184,24 @@ namespace Octokit.Reactive
return _client.Repository.Content.GetArchive(owner, name, archiveFormat, reference, timeout).ToObservable();
}
/// <summary>
/// Returns the contents of the root directory in a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
public IObservable<RepositoryContent> GetAllContents(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client
.Connection
.GetAndFlattenAllPages<RepositoryContent>(ApiUrls.RepositoryContent(owner, name, string.Empty));
}
/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
@@ -198,7 +216,7 @@ namespace Octokit.Reactive
/// <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)
public IObservable<RepositoryContent> 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<RepositoryContent>(ApiUrls.RepositoryContent(owner, name, path, reference));
}
/// <summary>
/// Returns the contents of the home directory in a repository.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the commit/branch/tag. Default: the repositorys default branch (usually master)</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
public IObservable<RepositoryContent> GetAllContentsByRef(string owner, string name, string reference)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(reference, "reference");
return _client.Connection.GetAndFlattenAllPages<RepositoryContent>(ApiUrls.RepositoryContent(owner, name, string.Empty, reference));
}
/// <summary>
/// Creates a commit that creates a new file in a repository.
/// </summary>
@@ -58,6 +58,22 @@ namespace Octokit.Tests.Clients
public class TheGetContentsMethod
{
[Fact]
public async Task ReturnsContentsByRef()
{
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.GetAllContentsByRef("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);
}
[Fact]
public async Task ReturnsContents()
{
@@ -67,9 +83,9 @@ namespace Octokit.Tests.Clients
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");
var contents = await contentsClient.GetAllContents("fake", "repo", "readme.md");
connection.Received().GetAll<RepositoryContent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/contents/readme.md?ref=master"));
connection.Received().GetAll<RepositoryContent>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/contents/readme.md"));
Assert.Equal(1, contents.Count);
}
}
+25 -1
View File
@@ -25,6 +25,18 @@ namespace Octokit
/// </returns>
Task<IReadOnlyList<RepositoryContent>> GetAllContents(string owner, string name, string path);
/// <summary>
/// Returns the contents of the root directory in a repository.
/// </summary>
/// <remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
Task<IReadOnlyList<RepositoryContent>> GetAllContents(string owner, string name);
/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
@@ -39,7 +51,19 @@ namespace Octokit
/// <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);
Task<IReadOnlyList<RepositoryContent>> GetAllContentsByRef(string owner, string name, string path, string reference);
/// <summary>
/// Returns the contents of the root directory in a repository.
/// </summary>
/// <remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the commit/branch/tag. Default: the repositorys default branch (usually master)</param>
/// <returns>
/// A collection of <see cref="RepositoryContent"/> representing the content at the specified path
/// </returns>
Task<IReadOnlyList<RepositoryContent>> GetAllContentsByRef(string owner, string name,string reference);
/// <summary>
/// Gets the preferred README for the specified repository.
+46 -3
View File
@@ -40,6 +40,26 @@ namespace Octokit
return await ApiConnection.GetAll<RepositoryContent>(url);
}
/// <summary>
/// Returns the contents of the root directory in a repository.
/// </summary>
/// <remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</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)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
var url = ApiUrls.RepositoryContent(owner, name, string.Empty);
return await ApiConnection.GetAll<RepositoryContent>(url);
}
/// <summary>
/// Returns the contents of a file or directory in a repository.
/// </summary>
@@ -54,15 +74,38 @@ namespace Octokit
/// <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)
public async Task<IReadOnlyList<RepositoryContent>> 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<RepositoryContent>(url);
}
/// <summary>
/// Returns the contents of the root directory in a repository.
/// </summary>
/// <remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The name of the commit/branch/tag. Default: the repositorys 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>> 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<RepositoryContent>(url);
}
/// <summary>