using System; using System.Reactive; using System.Reactive.Threading.Tasks; using Octokit.Reactive.Internal; namespace Octokit.Reactive { /// /// A client for GitHub's Issues API. /// /// /// See the Issues API documentation for more information. /// public class ObservableIssuesClient : IObservableIssuesClient { readonly IIssuesClient _client; readonly IConnection _connection; /// /// Client for managing assignees. /// public IObservableAssigneesClient Assignee { get; private set; } /// /// Client for managing comments. /// public IObservableIssueCommentsClient Comment { get; private set; } /// /// Client for reading various event information associated with issues/pull requests. /// This is useful both for display on issue/pull request information pages and also to /// determine who should be notified of comments. /// public IObservableIssuesEventsClient Events { get; private set; } /// /// Client for managing labels. /// public IObservableIssuesLabelsClient Labels { get; private set; } /// /// Client for managing milestones. /// public IObservableMilestonesClient Milestone { get; private set; } /// /// Client for reading the timeline of events for an issue /// public IObservableIssueTimelineClient Timeline { get; private set; } /// /// Client for locking/unlocking conversation on an issue /// public IObservableLockUnlockClient LockUnlock { get; protected set; } public ObservableIssuesClient(IGitHubClient client) { Ensure.ArgumentNotNull(client, nameof(client)); _client = client.Issue; _connection = client.Connection; Assignee = new ObservableAssigneesClient(client); Events = new ObservableIssuesEventsClient(client); Labels = new ObservableIssuesLabelsClient(client); Milestone = new ObservableMilestonesClient(client); Comment = new ObservableIssueCommentsClient(client); Timeline = new ObservableIssueTimelineClient(client); LockUnlock = new ObservableLockUnlockClient(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 issueNumber) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return _client.Get(owner, name, issueNumber).ToObservable(); } /// /// Gets a single Issue by number. /// /// /// http://developer.github.com/v3/issues/#get-a-single-issue /// /// The Id of the repository /// The issue number public IObservable Get(long repositoryId, int issueNumber) { return _client.Get(repositoryId, issueNumber).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(ApiOptions.None); } /// /// 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. /// /// Options for changing the API response /// /// Issues are sorted by the create date descending. /// http://developer.github.com/v3/issues/#list-issues /// public IObservable GetAllForCurrent(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return GetAllForCurrent(new IssueRequest(), options); } /// /// 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, nameof(request)); return GetAllForCurrent(request, ApiOptions.None); } /// /// 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 /// Options for changing the API response public IObservable GetAllForCurrent(IssueRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Issues(), request.ToParametersDictionary(), options); } /// /// 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 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 /// /// Options for changing the API response public IObservable GetAllForOwnedAndMemberRepositories(ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return GetAllForOwnedAndMemberRepositories(new IssueRequest(), options); } /// /// 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, nameof(request)); return GetAllForOwnedAndMemberRepositories(request, ApiOptions.None); } /// /// 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 /// Options for changing the API response public IObservable GetAllForOwnedAndMemberRepositories(IssueRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), options); } /// /// 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) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); return GetAllForOrganization(organization, ApiOptions.None); } /// /// 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 /// Options for changing the API response public IObservable GetAllForOrganization(string organization, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); Ensure.ArgumentNotNull(options, nameof(options)); return GetAllForOrganization(organization, new IssueRequest(), options); } /// /// 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, nameof(organization)); Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForOrganization(organization, request, ApiOptions.None); } /// /// 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 /// Options for changing the API response public IObservable GetAllForOrganization(string organization, IssueRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Issues(organization), request.ToParametersDictionary(), options); } /// /// 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 GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return GetAllForRepository(owner, name, ApiOptions.None); } /// /// Gets all open issues assigned to the authenticated user for the repository. /// /// /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// /// The Id of the repository public IObservable GetAllForRepository(long repositoryId) { return GetAllForRepository(repositoryId, ApiOptions.None); } /// /// 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 /// Options for changing the API response 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 GetAllForRepository(owner, name, new RepositoryIssueRequest(), options); } /// /// Gets all open issues assigned to the authenticated user for the repository. /// /// /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// /// The Id of the repository /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); return GetAllForRepository(repositoryId, new RepositoryIssueRequest(), options); } /// /// 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 GetAllForRepository(string owner, string name, RepositoryIssueRequest request) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForRepository(owner, name, request, ApiOptions.None); } /// /// Gets issues for a repository. /// /// /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// /// The Id of the repository /// Used to filter and sort the list of issues returned public IObservable GetAllForRepository(long repositoryId, RepositoryIssueRequest request) { Ensure.ArgumentNotNull(request, nameof(request)); return GetAllForRepository(repositoryId, request, ApiOptions.None); } /// /// 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 /// Options for changing the API response public IObservable GetAllForRepository(string owner, string name, RepositoryIssueRequest request, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), options); } /// /// Gets issues for a repository. /// /// /// http://developer.github.com/v3/issues/#list-issues-for-a-repository /// /// The Id of the repository /// Used to filter and sort the list of issues returned /// Options for changing the API response public IObservable GetAllForRepository(long repositoryId, RepositoryIssueRequest request, ApiOptions options) { Ensure.ArgumentNotNull(request, nameof(request)); Ensure.ArgumentNotNull(options, nameof(options)); return _connection.GetAndFlattenAllPages(ApiUrls.Issues(repositoryId), request.ToParametersDictionary(), options); } /// /// 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, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(newIssue, nameof(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 Id of the repository /// A instance describing the new issue to create public IObservable Create(long repositoryId, NewIssue newIssue) { Ensure.ArgumentNotNull(newIssue, nameof(newIssue)); return _client.Create(repositoryId, 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 issueNumber, IssueUpdate issueUpdate) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(issueUpdate, nameof(issueUpdate)); return _client.Update(owner, name, issueNumber, issueUpdate).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 Id of the repository /// The issue number /// An instance describing the changes to make to the issue /// public IObservable Update(long repositoryId, int issueNumber, IssueUpdate issueUpdate) { Ensure.ArgumentNotNull(issueUpdate, nameof(issueUpdate)); return _client.Update(repositoryId, issueNumber, issueUpdate).ToObservable(); } } }