using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Repository Comments API. /// /// /// See the Repository Comments API documentation for more information. /// public class ObservableRepositoryCommentsClient : IObservableRepositoryCommentsClient { readonly IRepositoryCommentsClient _client; readonly IConnection _connection; public ObservableRepositoryCommentsClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Repository.Comment; _connection = client.Connection; } /// /// Gets a single Repository Comment by number. /// /// The owner of the repository /// The name of the repository /// The comment id /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment 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 a single Repository Comment by number. /// /// The Id of the repository /// The comment id /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment public IObservable Get(int repositoryId, int number) { return _client.Get(repositoryId, number).ToObservable(); } /// /// Gets Commit Comments for a repository. /// /// The owner of the repository /// The name of the repository /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public IObservable GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return GetAllForRepository(owner, name, ApiOptions.None); } /// /// Gets Commit Comments for a repository. /// /// The Id of the repository /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public IObservable GetAllForRepository(int repositoryId) { return GetAllForRepository(repositoryId, ApiOptions.None); } /// /// Gets Commit Comments for a repository. /// /// The owner of the repository /// The name of the repository /// Options to change the API response /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public IObservable GetAllForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name), null, AcceptHeaders.ReactionsPreview, options); } /// /// Gets Commit Comments for a repository. /// /// The Id of the repository /// Options to change the API response /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository public IObservable GetAllForRepository(int repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId), null, AcceptHeaders.ReactionsPreview, options); } /// /// Gets Commit Comments for a specified Commit. /// /// The owner of the repository /// The name of the repository /// The sha of the commit /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public IObservable GetAllForCommit(string owner, string name, string sha) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); return GetAllForCommit(owner, name, sha, ApiOptions.None); } /// /// Gets Commit Comments for a specified Commit. /// /// The Id of the repository /// The sha of the commit /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public IObservable GetAllForCommit(int repositoryId, string sha) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); return GetAllForCommit(repositoryId, sha, ApiOptions.None); } /// /// Gets Commit Comments for a specified Commit. /// /// The owner of the repository /// The name of the repository /// The sha of the commit /// Options to change the API response /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public IObservable GetAllForCommit(string owner, string name, string sha, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name, sha), null, AcceptHeaders.ReactionsPreview, options); } /// /// Gets Commit Comments for a specified Commit. /// /// The Id of the repository /// The sha of the commit /// Options to change the API response /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit public IObservable GetAllForCommit(int repositoryId, string sha, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(options, "options"); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId, sha), null, AcceptHeaders.ReactionsPreview, options); } /// /// Creates a new Commit Comment for a specified Commit. /// /// The owner of the repository /// The name of the repository /// The sha reference of commit /// The new comment to add to the commit /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment 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(); } /// /// Creates a new Commit Comment for a specified Commit. /// /// The Id of the repository /// The sha reference of commit /// The new comment to add to the commit /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment public IObservable Create(int repositoryId, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); return _client.Create(repositoryId, sha, newCommitComment).ToObservable(); } /// /// Updates a specified Commit Comment. /// /// The owner of the repository /// The name of the repository /// The comment number /// The modified comment /// http://developer.github.com/v3/repos/comments/#update-a-commit-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(); } /// /// Updates a specified Commit Comment. /// /// The Id of the repository /// The comment number /// The modified comment /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment public IObservable Update(int repositoryId, int number, string commentUpdate) { Ensure.ArgumentNotNull(commentUpdate, "commentUpdate"); return _client.Update(repositoryId, number, commentUpdate).ToObservable(); } /// /// Deletes the specified Commit Comment /// /// The owner of the repository /// The name of the repository /// The comment id /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment public IObservable Delete(string owner, string name, int number) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); return _client.Delete(owner, name, number).ToObservable(); } /// /// Deletes the specified Commit Comment /// /// The Id of the repository /// The comment id /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment public IObservable Delete(int repositoryId, int number) { return _client.Delete(repositoryId, number).ToObservable(); } } }