moved function out to separate client

This commit is contained in:
Brendan Forster
2014-03-08 19:11:59 +11:00
parent ba82c4ea68
commit e6be0ad334
11 changed files with 77 additions and 36 deletions

View File

@@ -338,7 +338,7 @@ namespace Octokit.Reactive
/// <returns></returns> /// <returns></returns>
public IObservable<CompareResult> Compare(string owner, string name, string @base, string head) public IObservable<CompareResult> Compare(string owner, string name, string @base, string head)
{ {
return _client.Compare(owner, name, @base, head).ToObservable(); return _client.Commits.Compare(owner, name, @base, head).ToObservable();
} }
/// <summary> /// <summary>

View File

@@ -563,7 +563,7 @@ namespace Octokit.Tests.Clients
[Fact] [Fact]
public void EnsureNonNullArguments() public void EnsureNonNullArguments()
{ {
var client = new RepositoriesClient(Substitute.For<IApiConnection>()); var client = new RepositoryCommitsClient(Substitute.For<IApiConnection>());
Assert.Throws<ArgumentNullException>(() => client.Compare(null, "repo", "base", "head")); Assert.Throws<ArgumentNullException>(() => client.Compare(null, "repo", "base", "head"));
Assert.Throws<ArgumentException>(() => client.Compare("", "repo", "base", "head")); Assert.Throws<ArgumentException>(() => client.Compare("", "repo", "base", "head"));
@@ -583,7 +583,7 @@ namespace Octokit.Tests.Clients
{ {
var connection = Substitute.For<IApiConnection>(); var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection); var client = new RepositoryCommitsClient(connection);
client.Compare("owner", "repo", "base", "head"); client.Compare("owner", "repo", "base", "head");
@@ -596,7 +596,7 @@ namespace Octokit.Tests.Clients
{ {
var connection = Substitute.For<IApiConnection>(); var connection = Substitute.For<IApiConnection>();
var client = new RepositoriesClient(connection); var client = new RepositoryCommitsClient(connection);
client.Compare("owner", "repo", "base", "shiftkey/my-cool-branch"); client.Compare("owner", "repo", "base", "shiftkey/my-cool-branch");

View File

@@ -176,6 +176,14 @@ namespace Octokit
///</remarks> ///</remarks>
IStatisticsClient Statistics { get; } IStatisticsClient Statistics { get; }
/// <summary>
/// Client for GitHub's Repository Commits API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/commits/">Commits API documentation</a> for more details
///</remarks>
IRepositoryCommitsClient Commits { get; }
/// <summary> /// <summary>
/// Gets all the branches for the specified repository. /// Gets all the branches for the specified repository.
/// </summary> /// </summary>
@@ -264,16 +272,5 @@ namespace Octokit
/// <param name="update">New values to update the repository with</param> /// <param name="update">New values to update the repository with</param>
/// <returns>The updated <see cref="T:Octokit.Repository"/></returns> /// <returns>The updated <see cref="T:Octokit.Repository"/></returns>
Task<Repository> Edit(string owner, string name, RepositoryUpdate update); Task<Repository> Edit(string owner, string name, RepositoryUpdate update);
/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
Task<CompareResult> Compare(string owner, string name, string @base, string head);
} }
} }

View File

@@ -0,0 +1,19 @@
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
namespace Octokit
{
public interface IRepositoryCommitsClient
{
/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <returns></returns>
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")]
Task<CompareResult> Compare(string owner, string name, string @base, string head);
}
}

View File

@@ -28,6 +28,7 @@ namespace Octokit
Deployment = new DeploymentsClient(apiConnection); Deployment = new DeploymentsClient(apiConnection);
PullRequest = new PullRequestsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection);
RepositoryComments = new RepositoryCommentsClient(apiConnection); RepositoryComments = new RepositoryCommentsClient(apiConnection);
Commits = new RepositoryCommitsClient(apiConnection);
} }
/// <summary> /// <summary>
@@ -279,6 +280,14 @@ namespace Octokit
///</remarks> ///</remarks>
public IStatisticsClient Statistics { get; private set; } public IStatisticsClient Statistics { get; private set; }
/// <summary>
/// Client for GitHub's Repository Commits API
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/commits/">Commits API documentation</a> for more details
///</remarks>
public IRepositoryCommitsClient Commits { get; private set; }
/// <summary> /// <summary>
/// Client for managing pull requests. /// Client for managing pull requests.
/// </summary> /// </summary>
@@ -426,23 +435,5 @@ namespace Octokit
return ApiConnection.Get<Branch>(ApiUrls.RepoBranch(owner, repositoryName, branchName)); return ApiConnection.Get<Branch>(ApiUrls.RepoBranch(owner, repositoryName, branchName));
} }
/// <summary>
/// Compare two references in a repository
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="base">The reference to use as the base commit</param>
/// <param name="head">The reference to use as the head commit</param>
/// <returns></returns>
public Task<CompareResult> Compare(string owner, string name, string @base, string head)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "repositoryName");
Ensure.ArgumentNotNullOrEmptyString(@base, "base");
Ensure.ArgumentNotNullOrEmptyString(head, "head");
return ApiConnection.Get<CompareResult>(ApiUrls.RepoCompare(owner, name, @base, head));
}
} }
} }

View File

@@ -0,0 +1,24 @@
using System.Threading.Tasks;
namespace Octokit
{
public class RepositoryCommitsClient : IRepositoryCommitsClient
{
readonly IApiConnection _apiConnection;
public RepositoryCommitsClient(IApiConnection apiConnection)
{
_apiConnection = apiConnection;
}
public Task<CompareResult> Compare(string owner, string name, string @base, string head)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "repositoryName");
Ensure.ArgumentNotNullOrEmptyString(@base, "base");
Ensure.ArgumentNotNullOrEmptyString(head, "head");
return _apiConnection.Get<CompareResult>(ApiUrls.RepoCompare(owner, name, @base, head));
}
}
}

View File

@@ -311,6 +311,8 @@
<Compile Include="Models\Response\SearchCodeResult.cs" /> <Compile Include="Models\Response\SearchCodeResult.cs" />
<Compile Include="Models\Response\SearchIssuesResult.cs" /> <Compile Include="Models\Response\SearchIssuesResult.cs" />
<Compile Include="Models\Response\CompareResult.cs" /> <Compile Include="Models\Response\CompareResult.cs" />
<Compile Include="Clients\IRepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@@ -322,6 +322,8 @@
<Compile Include="Models\Response\SearchCodeResult.cs" /> <Compile Include="Models\Response\SearchCodeResult.cs" />
<Compile Include="Models\Response\SearchIssuesResult.cs" /> <Compile Include="Models\Response\SearchIssuesResult.cs" />
<Compile Include="Models\Response\CompareResult.cs" /> <Compile Include="Models\Response\CompareResult.cs" />
<Compile Include="Clients\IRepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" /> <Import Project="$(MSBuildExtensionsPath)\Novell\Novell.MonoDroid.CSharp.targets" />
</Project> </Project>

View File

@@ -317,6 +317,8 @@
<Compile Include="Models\Response\SearchCodeResult.cs" /> <Compile Include="Models\Response\SearchCodeResult.cs" />
<Compile Include="Models\Response\SearchIssuesResult.cs" /> <Compile Include="Models\Response\SearchIssuesResult.cs" />
<Compile Include="Models\Response\CompareResult.cs" /> <Compile Include="Models\Response\CompareResult.cs" />
<Compile Include="Clients\IRepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@@ -309,6 +309,8 @@
<Compile Include="Models\Response\SearchCodeResult.cs" /> <Compile Include="Models\Response\SearchCodeResult.cs" />
<Compile Include="Models\Response\SearchIssuesResult.cs" /> <Compile Include="Models\Response\SearchIssuesResult.cs" />
<Compile Include="Models\Response\CompareResult.cs" /> <Compile Include="Models\Response\CompareResult.cs" />
<Compile Include="Clients\IRepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CodeAnalysisDictionary Include="..\CustomDictionary.xml"> <CodeAnalysisDictionary Include="..\CustomDictionary.xml">

View File

@@ -53,10 +53,12 @@
<Link>Properties\SolutionInfo.cs</Link> <Link>Properties\SolutionInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Clients\ActivitiesClient.cs" /> <Compile Include="Clients\ActivitiesClient.cs" />
<Compile Include="Clients\IRepositoryCommitsClient.cs" />
<Compile Include="Clients\RepositoryCommentsClient.cs" /> <Compile Include="Clients\RepositoryCommentsClient.cs" />
<Compile Include="Clients\IRepositoryCommentsClient.cs" /> <Compile Include="Clients\IRepositoryCommentsClient.cs" />
<Compile Include="Clients\FeedsClient.cs" /> <Compile Include="Clients\FeedsClient.cs" />
<Compile Include="Clients\IFeedsClient.cs" /> <Compile Include="Clients\IFeedsClient.cs" />
<Compile Include="Clients\RepositoryCommitsClient.cs" />
<Compile Include="Exceptions\PrivateRepositoryQuotaExceededException.cs" /> <Compile Include="Exceptions\PrivateRepositoryQuotaExceededException.cs" />
<Compile Include="Exceptions\RepositoryExistsException.cs" /> <Compile Include="Exceptions\RepositoryExistsException.cs" />
<Compile Include="Helpers\ApiErrorExtensions.cs" /> <Compile Include="Helpers\ApiErrorExtensions.cs" />