Get All repo commits with request parameters

Implemented Get All using the available parameters wrapped in a
CommitRequest object.  Added unit tests and xml documentation along the
way.
This commit is contained in:
Timothy Haagenson
2014-07-09 09:38:02 -05:00
parent f1b772e4e8
commit a72e39f98b
13 changed files with 145 additions and 3 deletions

View File

@@ -23,5 +23,14 @@ namespace Octokit.Reactive
/// <param name="name">The name of the repository</param>
/// <returns></returns>
IObservable<GitHubCommit> GetAll(string owner, string name);
/// <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>
/// <param name="request">Used to filter list of commits returned</param>
/// <returns></returns>
IObservable<GitHubCommit> GetAll(string owner, string name, CommitRequest request);
}
}

View File

@@ -37,11 +37,25 @@ namespace Octokit.Reactive
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public IObservable<GitHubCommit> GetAll(string owner, string name)
{
return GetAll(owner, name, new CommitRequest());
}
/// <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>
/// <param name="request">Used to filter list of commits returned</param>
/// <returns></returns>
public IObservable<GitHubCommit> GetAll(string owner, string name, CommitRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
return _connection.GetAndFlattenAllPages<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name));
return _connection.GetAndFlattenAllPages<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name),
request.ToParametersDictionary());
}
}
}

View File

@@ -33,6 +33,46 @@ public class RepositoryCommitsClientTests : IDisposable
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetListOfCommitsBySha()
{
var request = new CommitRequest { Sha = "21599cd93657eeb7bde31989da61bd046c2ecd9e" };
var list = await _fixture.GetAll("octokit", "octokit.net", request);
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetListOfCommitsByPath()
{
var request = new CommitRequest { Path = "Octokit.Reactive/Clients" };
var list = await _fixture.GetAll("octokit", "octokit.net", request);
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetListOfCommitsByAuthor()
{
var request = new CommitRequest { Author = "haacked" };
var list = await _fixture.GetAll("octokit", "octokit.net", request);
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetListOfCommitsBySinceDate()
{
var request = new CommitRequest { Since = new DateTimeOffset(2014, 1, 1, 0, 0, 0, new TimeSpan(1, 0, 0)) };
var list = await _fixture.GetAll("octokit", "octokit.net", request);
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanGetListOfCommitsByUntilDate()
{
var request = new CommitRequest { Until = DateTimeOffset.Now };
var list = await _fixture.GetAll("octokit", "octokit.net", request);
Assert.NotEmpty(list);
}
[IntegrationTest]
public async Task CanCompareReferences()
{

View File

@@ -617,6 +617,8 @@ namespace Octokit.Tests.Clients
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null));
Assert.Throws<ArgumentException>(() => client.GetAll("owner", ""));
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "repo", null));
}
[Fact]
@@ -628,7 +630,8 @@ namespace Octokit.Tests.Clients
client.GetAll("owner", "name");
connection.Received()
.GetAll<GitHubCommit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/commits"));
.GetAll<GitHubCommit>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/commits"),
Arg.Any<Dictionary<string, string>>());
}
}
}

View File

@@ -24,5 +24,14 @@ namespace Octokit
/// <param name="name">The name of the repository</param>
/// <returns></returns>
Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name);
/// <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>
/// <param name="request">Used to filter list of commits returned</param>
/// <returns></returns>
Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name, CommitRequest request);
}
}

View File

@@ -37,11 +37,25 @@ namespace Octokit
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name)
{
return GetAll(owner, name, new CommitRequest());
}
/// <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>
/// <param name="request">Used to filter list of commits returned</param>
/// <returns></returns>
public Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name, CommitRequest request)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
return _apiConnection.GetAll<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name));
return _apiConnection.GetAll<GitHubCommit>(ApiUrls.RepositoryCommits(owner, name),
request.ToParametersDictionary());
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Diagnostics;
using System.Globalization;
namespace Octokit
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class CommitRequest : RequestParameters
{
public CommitRequest()
{
}
/// <summary>
/// SHA or branch to start listing commits from.
/// </summary>
public string Sha { get; set; }
/// <summary>
/// Only commits containing this file path will be returned.
/// </summary>
public string Path { get; set; }
/// <summary>
/// GitHub login or email address by which to filter by commit author.
/// </summary>
public string Author { get; set; }
/// <summary>
/// Only commits after this date will be returned.
/// </summary>
public DateTimeOffset? Since { get; set; }
/// <summary>
/// Only commits before this date will be returned.
/// </summary>
public DateTimeOffset? Until { get; set; }
internal string DebuggerDisplay
{
get
{
return String.Format(CultureInfo.InvariantCulture, "Sha: {0} ", Sha);
}
}
}
}

View File

@@ -325,6 +325,7 @@
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Models\Request\CommitRequest.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -335,6 +335,7 @@
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Models\Request\CommitRequest.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project>

View File

@@ -330,6 +330,7 @@
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Models\Request\CommitRequest.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -322,6 +322,7 @@
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Models\Request\CommitRequest.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -326,6 +326,7 @@
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Models\Request\CommitRequest.cs" />
</ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -72,6 +72,7 @@
<Compile Include="Helpers\SerializeNullAttribute.cs" />
<Compile Include="Http\ProductHeaderValue.cs" />
<Compile Include="Models\Request\NewDeployKey.cs" />
<Compile Include="Models\Request\CommitRequest.cs" />
<Compile Include="Models\Response\DeployKey.cs" />
<Compile Include="Models\Request\OauthLoginRequest.cs" />
<Compile Include="Models\Request\OauthTokenRequest.cs" />