Repository Commits Get All

Added the logic for getting all commits for a repository including unit
tests and XML docs
This commit is contained in:
Timothy Haagenson
2014-07-08 16:14:26 -05:00
parent 65a22f4d2c
commit f1b772e4e8
7 changed files with 98 additions and 2 deletions
@@ -15,5 +15,13 @@ namespace Octokit.Reactive
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
IObservable<CompareResult> Compare(string owner, string name, string @base, string @head);
/// <summary>
/// Gets all commits for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
IObservable<GitHubCommit> GetAll(string owner, string name);
}
}
@@ -1,15 +1,20 @@
using System;
using System.Reactive.Threading.Tasks;
using Octokit.Reactive.Internal;
namespace Octokit.Reactive
{
public class ObservableRepositoryCommitsClient : IObservableRepositoryCommitsClient
{
readonly IGitHubClient _client;
readonly IConnection _connection;
public ObservableRepositoryCommitsClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "client");
_client = client;
_connection = client.Connection;
}
/// <summary>
@@ -24,5 +29,19 @@ namespace Octokit.Reactive
{
return _client.Repository.Commits.Compare(owner, name, @base, head).ToObservable();
}
/// <summary>
/// Gets all commits for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public IObservable<GitHubCommit> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _connection.GetAndFlattenAllPages<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name));
}
}
}
@@ -26,6 +26,13 @@ public class RepositoryCommitsClientTests : IDisposable
_repository = _client.Repository.Create(new NewRepository { Name = repoName, AutoInit = true }).Result;
}
[IntegrationTest]
public async Task CanGetListOfCommits()
{
var list = await _fixture.GetAll("octokit", "octokit.net");
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanCompareReferences()
{
@@ -604,5 +604,32 @@ namespace Octokit.Tests.Clients
.Get<CompareResult>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/compare/base...shiftkey%2Fmy-cool-branch"), null);
}
}
public class TheGetAllCommitsMethod
{
[Fact]
public void EnsureNonNullArguments()
{
var client = new RepositoryCommitsClient(Substitute.For<IApiConnection>());
Assert.Throws<ArgumentNullException>(() => client.GetAll(null, "repo"));
Assert.Throws<ArgumentException>(() => client.GetAll("", "repo"));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null));
Assert.Throws<ArgumentException>(() => client.GetAll("owner", ""));
}
[Fact]
public void GetsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new RepositoryCommitsClient(connection);
client.GetAll("owner", "name");
connection.Received()
.GetAll<GitHubCommit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/commits"));
}
}
}
}
+10 -1
View File
@@ -1,4 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace Octokit
@@ -15,5 +16,13 @@ namespace Octokit
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
Task<CompareResult> Compare(string owner, string name, string @base, string head);
/// <summary>
/// Gets all commits for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name);
}
}
+16 -1
View File
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
@@ -28,5 +29,19 @@ namespace Octokit
return _apiConnection.Get<CompareResult>(ApiUrls.RepoCompare(owner, name, @base, head));
}
/// <summary>
/// Gets all commits for a given repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _apiConnection.GetAll<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name));
}
}
}
+11
View File
@@ -1056,6 +1056,17 @@ namespace Octokit
return "repos/{0}/{1}/tags".FormatUri(owner, name);
}
/// <summary>
/// Returns the <see cref="Uri"/> for repository commits.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public static Uri RepositoryCommits(string owner, string name)
{
return "repos/{0}/{1}/commits".FormatUri(owner, name);
}
/// <summary>
/// Returns the <see cref="Uri"/> for comparing two commits.
/// </summary>