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; }
public ObservableIssuesClient(IGitHubClient client)
{
Ensure.ArgumentNotNull(client, "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);
}
///
/// 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 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(int repositoryId, int number)
{
return _client.Get(repositoryId, 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(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, "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, "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, "request");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Issues(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, 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, "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, "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, "request");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.IssuesForOwnedAndMember(), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, 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, "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, "organization");
Ensure.ArgumentNotNull(options, "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, "organization");
Ensure.ArgumentNotNull(request, "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, "organization");
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Issues(organization), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, 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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "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(int 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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "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(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "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(int repositoryId, RepositoryIssueRequest request)
{
Ensure.ArgumentNotNull(request, "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, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "options");
return _connection.GetAndFlattenAllPages(ApiUrls.Issues(owner, name), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, 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(int repositoryId, RepositoryIssueRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, "request");
Ensure.ArgumentNotNull(options, "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, "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 Id of the repository
/// A instance describing the new issue to create
public IObservable Create(int repositoryId, NewIssue newIssue)
{
Ensure.ArgumentNotNull(newIssue, "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 number, IssueUpdate issueUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(issueUpdate, "issueUpdate");
return _client.Update(owner, name, number, 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(int repositoryId, int number, IssueUpdate issueUpdate)
{
Ensure.ArgumentNotNull(issueUpdate, "issueUpdate");
return _client.Update(repositoryId, number, issueUpdate).ToObservable();
}
///
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
///
/// https://developer.github.com/v3/issues/#lock-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue number
public IObservable Lock(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Lock(owner, name, number).ToObservable();
}
///
/// Locks an issue for the specified repository. Issue owners and users with push access can lock an issue.
///
/// https://developer.github.com/v3/issues/#lock-an-issue
/// The Id of the repository
/// The issue number
public IObservable Lock(int repositoryId, int number)
{
return _client.Lock(repositoryId, number).ToObservable();
}
///
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
///
/// https://developer.github.com/v3/issues/#unlock-an-issue
/// The owner of the repository
/// The name of the repository
/// The issue number
public IObservable Unlock(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return _client.Unlock(owner, name, number).ToObservable();
}
///
/// Unlocks an issue for the specified repository. Issue owners and users with push access can unlock an issue.
///
/// https://developer.github.com/v3/issues/#unlock-an-issue
/// The Id of the repository
/// The issue number
public IObservable Unlock(int repositoryId, int number)
{
return _client.Unlock(repositoryId, number).ToObservable();
}
}
}