using System; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { public class ObservableIssuesClient : IObservableIssuesClient { readonly IIssuesClient _client; readonly IConnection _connection; public IObservableAssigneesClient Assignee { get; private set; } public IObservableMilestonesClient Milestone { get; private set; } public IObservableIssueCommentsClient Comments { get; private set; } public ObservableIssuesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, "client"); _client = client.Issue; _connection = client.Connection; Assignee = new ObservableAssigneesClient(client); Milestone = new ObservableMilestonesClient(client); Comments = new ObservableIssueCommentsClient(client); } /// /// Gets a single Issue by number./// /// /// http://developer.github.com/v3/issues/#get-a-single-issue /// /// The owner of the repository /// The name of the repository /// The issue number /// 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 all open issues assigned to the authenticated user across all the authenticated user’s visible /// repositories including owned repositories, member repositories, and organization repositories. /// /// /// Issues are sorted by the create date descending. /// http://developer.github.com/v3/issues/#list-issues /// /// public IObservable GetAllForCurrent() { return GetAllForCurrent(new IssueRequest()); } /// /// Gets all issues across all the authenticated user’s visible repositories including owned repositories, /// member repositories, and organization repositories. /// /// /// http://developer.github.com/v3/issues/#list-issues /// /// Used to filter and sort the list of issues returned /// public IObservable GetAllForCurrent(IssueRequest request) { Ensure.ArgumentNotNull(request, "request"); return _connection.GetAndFlattenAllPages(ApiUrls.Issues(), request.ToParametersDictionary()); } /// /// Gets all open issues assigned to the authenticated user across owned and member repositories for the /// authenticated user. /// /// /// Issues are sorted by the create date descending. /// http://developer.github.com/v3/issues/#list-issues /// /// public IObservable GetAllForOwnedAndMemberRepositories() { return GetAllForOwnedAndMemberRepositories(new IssueRequest()); } /// /// Gets all issues across owned and member repositories for the authenticated user. /// /// /// http://developer.github.com/v3/issues/#list-issues /// /// Used to filter and sort the list of issues returned /// public IObservable GetAllForOwnedAndMemberRepositories(IssueRequest request) { Ensure.ArgumentNotNull(request, "request"); return _connection.GetAndFlattenAllPages(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary()); } /// /// Gets all open issues assigned to the authenticated user for a given organization for the authenticated user. /// /// /// http://developer.github.com/v3/issues/#list-issues /// /// The name of the organization /// public IObservable GetAllForOrganization(string organization) { return GetAllForOrganization(organization, new IssueRequest()); } /// /// Gets all issues for a given organization for the authenticated user. /// /// /// http://developer.github.com/v3/issues/#list-issues /// /// The name of the organization /// Used to filter and sort the list of issues returned /// public IObservable GetAllForOrganization(string organization, IssueRequest request) { Ensure.ArgumentNotNullOrEmptyString(organization, "organization"); Ensure.ArgumentNotNull(request, "request"); return _connection.GetAndFlattenAllPages(ApiUrls.Issues(organization), request.ToParametersDictionary()); } /// /// Gets all open issues assigned to the authenticated user for the repository. /// /// /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// /// The owner of the repository /// The name of the repository /// public IObservable GetForRepository(string owner, string name) { return GetForRepository(owner, name, new RepositoryIssueRequest()); } /// /// Gets issues for a repository. /// /// /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// /// The owner of the repository /// The name of the repository /// Used to filter and sort the list of issues returned /// public IObservable GetForRepository(string owner, string name, RepositoryIssueRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(request, "request"); return _connection.GetAndFlattenAllPages(ApiUrls.Issues(owner, name), request.ToParametersDictionary()); } /// /// Creates an issue for the specified repository. Any user with pull access to a repository can create an /// issue. /// /// http://developer.github.com/v3/issues/#create-an-issue /// The owner of the repository /// The name of the repository /// A instance describing the new issue to create /// public IObservable Create(string owner, string name, NewIssue newIssue) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(newIssue, "newIssue"); return _client.Create(owner, name, newIssue).ToObservable(); } /// /// Creates an issue for the specified repository. Any user with pull access to a repository can create an /// issue. /// /// http://developer.github.com/v3/issues/#create-an-issue /// The owner of the repository /// The name of the repository /// The issue number /// An instance describing the changes to make to the issue /// /// public IObservable Update(string owner, string name, int number, IssueUpdate issueUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(issueUpdate, "issueUpdate"); return _client.Update(owner, name, number, issueUpdate).ToObservable(); } } }