From 082658083c5b139fd52d6f79e843cdd1a5eff679 Mon Sep 17 00:00:00 2001 From: Will Froese Date: Thu, 27 Feb 2014 22:04:26 -0500 Subject: [PATCH] Add IObservableRepositoryCommentsClient as well as an implementation --- .../Clients/IObservableRepositoriesClient.cs | 8 ++ .../IObservableRepositoryCommentsClient.cs | 72 +++++++++++ .../Clients/ObservableRepositoriesClient.cs | 3 + .../ObservableRepositoryCommentsClient.cs | 122 ++++++++++++++++++ Octokit.Reactive/Octokit.Reactive-Mono.csproj | 2 + .../Octokit.Reactive-MonoAndroid.csproj | 2 + .../Octokit.Reactive-Monotouch.csproj | 2 + Octokit.Reactive/Octokit.Reactive.csproj | 2 + Octokit/Clients/IRepositoriesClient.cs | 8 ++ Octokit/Clients/IRepositoryCommentsClient.cs | 2 +- Octokit/Clients/RepositoriesClient.cs | 9 ++ Octokit/Clients/RepositoryCommentsClient.cs | 2 +- 12 files changed, 232 insertions(+), 2 deletions(-) create mode 100644 Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs create mode 100644 Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs diff --git a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs index 3888b188..639acde1 100644 --- a/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/IObservableRepositoriesClient.cs @@ -116,6 +116,14 @@ namespace Octokit.Reactive /// IObservableStatisticsClient Statistics { get; } + /// + /// Client for GitHub's Repository Comments API. + /// + /// + /// See the Repository Comments API documentation for more information. + /// + IObservableRepositoryCommentsClient RepositoryComments { get; } + /// /// Gets all the branches for the specified repository. /// diff --git a/Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs b/Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs new file mode 100644 index 00000000..2a1faef4 --- /dev/null +++ b/Octokit.Reactive/Clients/IObservableRepositoryCommentsClient.cs @@ -0,0 +1,72 @@ +using System; +using System.Diagnostics.CodeAnalysis; +using System.Reactive; + +namespace Octokit.Reactive +{ + public interface IObservableRepositoryCommentsClient + { + /// + /// Gets a single Repository Comment by number. + /// + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// + [SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", + Justification = "Method makes a network request")] + IObservable Get(string owner, string name, int number); + + /// + /// Gets Commit Comments for a repository. + /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + /// The owner of the repository + /// The name of the repository + /// + IObservable GetForRepository(string owner, string name); + + /// + /// Gets Commit Comments for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + /// The owner of the repository + /// The name of the repository + /// The sha of the commit + /// + IObservable GetForCommit(string owner, string name, string sha); + + /// + /// Creates a new Commit Comment for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The sha reference of commit + /// The new comment to add to the commit + /// + IObservable Create(string owner, string name, string sha, NewCommitComment newCommitComment); + + /// + /// Updates a specified Commit Comment. + /// + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment number + /// The modified comment + /// + IObservable Update(string owner, string name, int number, string commentUpdate); + + /// + /// Deletes the specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// + IObservable Delete(string owner, string name, int number); + } +} diff --git a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs index 63a5b254..f05c9ddb 100644 --- a/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs +++ b/Octokit.Reactive/Clients/ObservableRepositoriesClient.cs @@ -24,6 +24,7 @@ namespace Octokit.Reactive Deployment = new ObservableDeploymentsClient(client); Statistics = new ObservableStatisticsClient(client); PullRequest = new ObservablePullRequestsClient(client); + RepositoryComments = new ObservableRepositoryCommentsClient(client); } /// @@ -180,6 +181,8 @@ namespace Octokit.Reactive /// public IObservableStatisticsClient Statistics { get; private set; } + public IObservableRepositoryCommentsClient RepositoryComments { get; private set; } + /// /// Gets all the branches for the specified repository. /// diff --git a/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs b/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs new file mode 100644 index 00000000..492792e8 --- /dev/null +++ b/Octokit.Reactive/Clients/ObservableRepositoryCommentsClient.cs @@ -0,0 +1,122 @@ +using System; +using System.Reactive; +using System.Reactive.Threading.Tasks; +using Octokit.Reactive.Internal; + +namespace Octokit.Reactive +{ + public class ObservableRepositoryCommentsClient : IObservableRepositoryCommentsClient + { + readonly IRepositoryCommentsClient _client; + readonly IConnection _connection; + + public ObservableRepositoryCommentsClient(IGitHubClient client) + { + Ensure.ArgumentNotNull(client, "client"); + + _client = client.Repository.RepositoryComments; + _connection = client.Connection; + } + + /// + /// Gets a single Repository Comment by number. + /// + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// + public IObservable Get(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.Get(owner, name, number).ToObservable(); + } + + /// + /// Gets Commit Comments for a repository. + /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + /// The owner of the repository + /// The name of the repository + /// + public IObservable GetForRepository(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name)); + } + + /// + /// Gets Commit Comments for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + /// The owner of the repository + /// The name of the repository + /// The sha of the commit + /// + public IObservable GetForCommit(string owner, string name, string sha) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + + return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name, sha)); + } + + /// + /// Creates a new Commit Comment for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The sha reference of commit + /// The new comment to add to the commit + /// + public IObservable Create(string owner, string name, string sha, NewCommitComment newCommitComment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); + + return _client.Create(owner, name, sha, newCommitComment).ToObservable(); + } + + /// + /// Updates a specified Commit Comment. + /// + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment number + /// The modified comment + /// + public IObservable Update(string owner, string name, int number, string commentUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(commentUpdate, "commentUpdate"); + + return _client.Update(owner, name, number, commentUpdate).ToObservable(); + } + + /// + /// Deletes the specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// + public IObservable Delete(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return _client.Delete(owner, name, number).ToObservable(); + } + } +} diff --git a/Octokit.Reactive/Octokit.Reactive-Mono.csproj b/Octokit.Reactive/Octokit.Reactive-Mono.csproj index d3c9a130..5dc511fd 100644 --- a/Octokit.Reactive/Octokit.Reactive-Mono.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Mono.csproj @@ -139,6 +139,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj index 885d6aa1..cd53c5a2 100644 --- a/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj +++ b/Octokit.Reactive/Octokit.Reactive-MonoAndroid.csproj @@ -148,6 +148,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj index f571279c..c8657d7f 100644 --- a/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj +++ b/Octokit.Reactive/Octokit.Reactive-Monotouch.csproj @@ -143,6 +143,8 @@ + + diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 5bd37f71..33216b99 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -73,6 +73,8 @@ Properties\SolutionInfo.cs + + diff --git a/Octokit/Clients/IRepositoriesClient.cs b/Octokit/Clients/IRepositoriesClient.cs index 8c700b5e..2989c610 100644 --- a/Octokit/Clients/IRepositoriesClient.cs +++ b/Octokit/Clients/IRepositoriesClient.cs @@ -22,6 +22,14 @@ namespace Octokit /// IPullRequestsClient PullRequest { get; } + /// + /// Client for managing commit comments in a repository. + /// + /// + /// See the Repository Comments API documentation for more information. + /// + IRepositoryCommentsClient RepositoryComments { get; } + /// /// Creates a new repository for the current user. /// diff --git a/Octokit/Clients/IRepositoryCommentsClient.cs b/Octokit/Clients/IRepositoryCommentsClient.cs index 2ffa9649..cd47654b 100644 --- a/Octokit/Clients/IRepositoryCommentsClient.cs +++ b/Octokit/Clients/IRepositoryCommentsClient.cs @@ -44,7 +44,7 @@ namespace Octokit Task> GetForCommit(string owner, string name, string sha); /// - /// Creates a new Commit Comment for a specified Issue. + /// Creates a new Commit Comment for a specified Commit. /// /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment /// The owner of the repository diff --git a/Octokit/Clients/RepositoriesClient.cs b/Octokit/Clients/RepositoriesClient.cs index 38c3f920..f46e65bd 100644 --- a/Octokit/Clients/RepositoriesClient.cs +++ b/Octokit/Clients/RepositoriesClient.cs @@ -27,6 +27,7 @@ namespace Octokit Statistics = new StatisticsClient(apiConnection); Deployment = new DeploymentsClient(apiConnection); PullRequest = new PullRequestsClient(apiConnection); + RepositoryComments = new RepositoryCommentsClient(apiConnection); } /// @@ -286,6 +287,14 @@ namespace Octokit /// public IPullRequestsClient PullRequest { get; private set; } + /// + /// Client for managing commit comments in a repository. + /// + /// + /// See the Repository Comments API documentation for more information. + /// + public IRepositoryCommentsClient RepositoryComments { get; private set; } + /// /// Gets all the branches for the specified repository. /// diff --git a/Octokit/Clients/RepositoryCommentsClient.cs b/Octokit/Clients/RepositoryCommentsClient.cs index b5138b0b..8f7ccac4 100644 --- a/Octokit/Clients/RepositoryCommentsClient.cs +++ b/Octokit/Clients/RepositoryCommentsClient.cs @@ -70,7 +70,7 @@ namespace Octokit } /// - /// Creates a new Commit Comment for a specified Issue. + /// Creates a new Commit Comment for a specified Commit. /// /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment /// The owner of the repository