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, nameof(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, long commentId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Get(owner, name, commentId).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(long repositoryId, long commentId) { return _client.Get(repositoryId, commentId).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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(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(long 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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name), null, 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(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId), null, 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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(sha, nameof(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(long repositoryId, string sha) { Ensure.ArgumentNotNullOrEmptyString(sha, nameof(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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(owner, name, sha), null, 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(long repositoryId, string sha, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.CommitComments(repositoryId, sha), null, 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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha)); Ensure.ArgumentNotNull(newCommitComment, nameof(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(long repositoryId, string sha, NewCommitComment newCommitComment) { Ensure.ArgumentNotNullOrEmptyString(sha, nameof(sha)); Ensure.ArgumentNotNull(newCommitComment, nameof(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 id /// The modified comment /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment public IObservable Update(string owner, string name, long commentId, string commentUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(commentUpdate, nameof(commentUpdate)); return _client.Update(owner, name, commentId, commentUpdate).ToObservable(); } /// /// Updates a specified Commit Comment. /// /// The Id of the repository /// The comment id /// The modified comment /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment public IObservable Update(long repositoryId, long commentId, string commentUpdate) { Ensure.ArgumentNotNull(commentUpdate, nameof(commentUpdate)); return _client.Update(repositoryId, commentId, 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, long commentId) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Delete(owner, name, commentId).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(long repositoryId, long commentId) { return _client.Delete(repositoryId, commentId).ToObservable(); } } }