From e6be0ad334f0ca353146aa804517c4346661e35a Mon Sep 17 00:00:00 2001 From: Brendan Forster Date: Sat, 8 Mar 2014 19:11:59 +1100 Subject: [PATCH] moved function out to separate client --- .../Clients/ObservableRepositoriesClient.cs | 2 +- .../Clients/RepositoriesClientTests.cs | 12 ++++----- Octokit/Clients/IRepositoriesClient.cs | 19 ++++++------- Octokit/Clients/IRepositoryCommitsClient.cs | 19 +++++++++++++ Octokit/Clients/RepositoriesClient.cs | 27 +++++++------------ Octokit/Clients/RepositoryCommitsClient.cs | 24 +++++++++++++++++ Octokit/Octokit-Mono.csproj | 2 ++ Octokit/Octokit-MonoAndroid.csproj | 2 ++ Octokit/Octokit-Monotouch.csproj | 2 ++ Octokit/Octokit-netcore45.csproj | 2 ++ Octokit/Octokit.csproj | 2 ++ 11 files changed, 77 insertions(+), 36 deletions(-) create mode 100644 Octokit/Clients/IRepositoryCommitsClient.cs create mode 100644 Octokit/Clients/RepositoryCommitsClient.cs diff --git a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs index a6f99e4b..d84588c2 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs @@ -338,7 +338,7 @@ namespace Octokit.Reactive /// public IObservable 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(); } /// diff --git a/Octokit.Tests/Clients/RepositoriesClientTests.cs b/Octokit.Tests/Clients/RepositoriesClientTests.cs index 9f7b1812..d995cffb 100644 --- a/Octokit.Tests/Clients/RepositoriesClientTests.cs +++ b/Octokit.Tests/Clients/RepositoriesClientTests.cs @@ -35,7 +35,7 @@ namespace Octokit.Tests.Clients await AssertEx.Throws(async () => await client.Create(null)); await AssertEx.Throws(async () => await client.Create(new NewRepository { Name = null })); } - + [Fact] public void UsesTheUserReposUrl() { @@ -345,9 +345,9 @@ namespace Octokit.Tests.Clients var readme = await reposEndpoint.GetReadme("fake", "repo"); Assert.Equal("README.md", readme.Name); - connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/readme"), + connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/readme"), null); - connection.DidNotReceive().GetHtml(Arg.Is(u => u.ToString() == "https://github.example.com/readme"), + connection.DidNotReceive().GetHtml(Arg.Is(u => u.ToString() == "https://github.example.com/readme"), null); var htmlReadme = await readme.GetHtmlContent(); Assert.Equal("README", htmlReadme); @@ -563,7 +563,7 @@ namespace Octokit.Tests.Clients [Fact] public void EnsureNonNullArguments() { - var client = new RepositoriesClient(Substitute.For()); + var client = new RepositoryCommitsClient(Substitute.For()); Assert.Throws(() => client.Compare(null, "repo", "base", "head")); Assert.Throws(() => client.Compare("", "repo", "base", "head")); @@ -583,7 +583,7 @@ namespace Octokit.Tests.Clients { var connection = Substitute.For(); - var client = new RepositoriesClient(connection); + var client = new RepositoryCommitsClient(connection); client.Compare("owner", "repo", "base", "head"); @@ -596,7 +596,7 @@ namespace Octokit.Tests.Clients { var connection = Substitute.For(); - var client = new RepositoriesClient(connection); + var client = new RepositoryCommitsClient(connection); client.Compare("owner", "repo", "base", "shiftkey/my-cool-branch"); diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 15996b12..175bc203 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -176,6 +176,14 @@ namespace Octokit /// IStatisticsClient Statistics { get; } + /// + /// Client for GitHub's Repository Commits API + /// + /// + /// See the Commits API documentation for more details + /// + IRepositoryCommitsClient Commits { get; } + /// /// Gets all the branches for the specified repository. /// @@ -264,16 +272,5 @@ namespace Octokit /// New values to update the repository with /// The updated Task Edit(string owner, string name, RepositoryUpdate update); - - /// - /// Compare two references in a repository - /// - /// The owner of the repository - /// The name of the repository - /// The reference to use as the base commit - /// The reference to use as the head commit - /// - [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")] - Task Compare(string owner, string name, string @base, string head); } } diff --git a/Octokit/Clients/IRepositoryCommitsClient.cs b/Octokit/Clients/IRepositoryCommitsClient.cs new file mode 100644 index 00000000..567792b9 --- /dev/null +++ b/Octokit/Clients/IRepositoryCommitsClient.cs @@ -0,0 +1,19 @@ +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace Octokit +{ + public interface IRepositoryCommitsClient + { + /// + /// Compare two references in a repository + /// + /// The owner of the repository + /// The name of the repository + /// The reference to use as the base commit + /// The reference to use as the head commit + /// + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "base")] + Task Compare(string owner, string name, string @base, string head); + } +} diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 4806ab87..fc22e459 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -28,6 +28,7 @@ namespace Octokit Deployment = new DeploymentsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection); RepositoryComments = new RepositoryCommentsClient(apiConnection); + Commits = new RepositoryCommitsClient(apiConnection); } /// @@ -279,6 +280,14 @@ namespace Octokit /// public IStatisticsClient Statistics { get; private set; } + /// + /// Client for GitHub's Repository Commits API + /// + /// + /// See the Commits API documentation for more details + /// + public IRepositoryCommitsClient Commits { get; private set; } + /// /// Client for managing pull requests. /// @@ -426,23 +435,5 @@ namespace Octokit return ApiConnection.Get(ApiUrls.RepoBranch(owner, repositoryName, branchName)); } - - /// - /// Compare two references in a repository - /// - /// The owner of the repository - /// The name of the repository - /// The reference to use as the base commit - /// The reference to use as the head commit - /// - public Task 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(ApiUrls.RepoCompare(owner, name, @base, head)); - } } } diff --git a/Octokit/Clients/RepositoryCommitsClient.cs b/Octokit/Clients/RepositoryCommitsClient.cs new file mode 100644 index 00000000..bc0a541a --- /dev/null +++ b/Octokit/Clients/RepositoryCommitsClient.cs @@ -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 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(ApiUrls.RepoCompare(owner, name, @base, head)); + } + } +} \ No newline at end of file diff --git a/Octokit/Octokit-Mono.csproj b/Octokit/Octokit-Mono.csproj index cd62c96c..6af73628 100644 --- a/Octokit/Octokit-Mono.csproj +++ b/Octokit/Octokit-Mono.csproj @@ -311,6 +311,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index c1630543..c29e354c 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -322,6 +322,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 603a097f..a4839dad 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -317,6 +317,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-netcore45.csproj b/Octokit/Octokit-netcore45.csproj index 14929305..5dc78b11 100644 --- a/Octokit/Octokit-netcore45.csproj +++ b/Octokit/Octokit-netcore45.csproj @@ -309,6 +309,8 @@ + + diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 076d7c93..153347aa 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -53,10 +53,12 @@ Properties\SolutionInfo.cs + +