mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-20 06:05:12 +00:00
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:
@@ -23,5 +23,14 @@ namespace Octokit.Reactive
|
|||||||
/// <param name="name">The name of the repository</param>
|
/// <param name="name">The name of the repository</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
IObservable<GitHubCommit> GetAll(string owner, string name);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,11 +37,25 @@ namespace Octokit.Reactive
|
|||||||
/// <param name="name">The name of the repository</param>
|
/// <param name="name">The name of the repository</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public IObservable<GitHubCommit> GetAll(string owner, string name)
|
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(owner, "owner");
|
||||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,46 @@ public class RepositoryCommitsClientTests : IDisposable
|
|||||||
Assert.NotEmpty(list);
|
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]
|
[IntegrationTest]
|
||||||
public async Task CanCompareReferences()
|
public async Task CanCompareReferences()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -617,6 +617,8 @@ namespace Octokit.Tests.Clients
|
|||||||
|
|
||||||
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null));
|
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", null));
|
||||||
Assert.Throws<ArgumentException>(() => client.GetAll("owner", ""));
|
Assert.Throws<ArgumentException>(() => client.GetAll("owner", ""));
|
||||||
|
|
||||||
|
Assert.Throws<ArgumentNullException>(() => client.GetAll("owner", "repo", null));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -628,7 +630,8 @@ namespace Octokit.Tests.Clients
|
|||||||
client.GetAll("owner", "name");
|
client.GetAll("owner", "name");
|
||||||
|
|
||||||
connection.Received()
|
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>>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,14 @@ namespace Octokit
|
|||||||
/// <param name="name">The name of the repository</param>
|
/// <param name="name">The name of the repository</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,11 +37,25 @@ namespace Octokit
|
|||||||
/// <param name="name">The name of the repository</param>
|
/// <param name="name">The name of the repository</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public Task<IReadOnlyList<GitHubCommit>> GetAll(string owner, string name)
|
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(owner, "owner");
|
||||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
47
Octokit/Models/Request/CommitRequest.cs
Normal file
47
Octokit/Models/Request/CommitRequest.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -325,6 +325,7 @@
|
|||||||
<Compile Include="Models\Request\NewDeployKey.cs" />
|
<Compile Include="Models\Request\NewDeployKey.cs" />
|
||||||
<Compile Include="Models\Response\DeployKey.cs" />
|
<Compile Include="Models\Response\DeployKey.cs" />
|
||||||
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
||||||
|
<Compile Include="Models\Request\CommitRequest.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -335,6 +335,7 @@
|
|||||||
<Compile Include="Models\Request\NewDeployKey.cs" />
|
<Compile Include="Models\Request\NewDeployKey.cs" />
|
||||||
<Compile Include="Models\Response\DeployKey.cs" />
|
<Compile Include="Models\Response\DeployKey.cs" />
|
||||||
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
||||||
|
<Compile Include="Models\Request\CommitRequest.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -330,6 +330,7 @@
|
|||||||
<Compile Include="Models\Request\NewDeployKey.cs" />
|
<Compile Include="Models\Request\NewDeployKey.cs" />
|
||||||
<Compile Include="Models\Response\DeployKey.cs" />
|
<Compile Include="Models\Response\DeployKey.cs" />
|
||||||
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
||||||
|
<Compile Include="Models\Request\CommitRequest.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -322,6 +322,7 @@
|
|||||||
<Compile Include="Models\Request\NewDeployKey.cs" />
|
<Compile Include="Models\Request\NewDeployKey.cs" />
|
||||||
<Compile Include="Models\Response\DeployKey.cs" />
|
<Compile Include="Models\Response\DeployKey.cs" />
|
||||||
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
||||||
|
<Compile Include="Models\Request\CommitRequest.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||||
|
|||||||
@@ -326,6 +326,7 @@
|
|||||||
<Compile Include="Models\Request\NewDeployKey.cs" />
|
<Compile Include="Models\Request\NewDeployKey.cs" />
|
||||||
<Compile Include="Models\Response\DeployKey.cs" />
|
<Compile Include="Models\Response\DeployKey.cs" />
|
||||||
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
||||||
|
<Compile Include="Models\Request\CommitRequest.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
<CodeAnalysisDictionary Include="..\CustomDictionary.xml">
|
||||||
|
|||||||
@@ -72,6 +72,7 @@
|
|||||||
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
<Compile Include="Helpers\SerializeNullAttribute.cs" />
|
||||||
<Compile Include="Http\ProductHeaderValue.cs" />
|
<Compile Include="Http\ProductHeaderValue.cs" />
|
||||||
<Compile Include="Models\Request\NewDeployKey.cs" />
|
<Compile Include="Models\Request\NewDeployKey.cs" />
|
||||||
|
<Compile Include="Models\Request\CommitRequest.cs" />
|
||||||
<Compile Include="Models\Response\DeployKey.cs" />
|
<Compile Include="Models\Response\DeployKey.cs" />
|
||||||
<Compile Include="Models\Request\OauthLoginRequest.cs" />
|
<Compile Include="Models\Request\OauthLoginRequest.cs" />
|
||||||
<Compile Include="Models\Request\OauthTokenRequest.cs" />
|
<Compile Include="Models\Request\OauthTokenRequest.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user