using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
///
/// A client for GitHub's Issues API.
///
///
/// See the Issues API documentation for more information.
///
public class IssuesClient : ApiClient, IIssuesClient
{
///
/// Instantiates a new GitHub Issues API client.
///
/// An API connection
public IssuesClient(IApiConnection apiConnection) : base(apiConnection)
{
Assignee = new AssigneesClient(apiConnection);
Events = new IssuesEventsClient(apiConnection);
Labels = new IssuesLabelsClient(apiConnection);
Milestone = new MilestonesClient(apiConnection);
Comment = new IssueCommentsClient(apiConnection);
Timeline = new IssueTimelineClient(apiConnection);
}
///
/// Client for managing assignees.
///
public IAssigneesClient Assignee { 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 IIssuesEventsClient Events { get; private set; }
///
/// Client for managing labels.
///
public IIssuesLabelsClient Labels { get; private set; }
///
/// Client for managing milestones.
///
public IMilestonesClient Milestone { get; private set; }
///
/// Client for managing comments.
///
public IIssueCommentsClient Comment { get; private set; }
///
/// Client for reading the timeline of events for an issue
///
public IIssueTimelineClient Timeline { get; private set; }
///
/// 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
[Preview("squirrel-girl")]
[ManualRoute("GET", "/repos/{owner}/{repo}/issues/{issue_number}")]
public Task Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Get(ApiUrls.Issue(owner, name, number), null, AcceptHeaders.ReactionsPreview);
}
///
/// Gets a single Issue by number.
///
///
/// http://developer.github.com/v3/issues/#get-a-single-issue
///
/// The Id of the repository
/// The issue number
[Preview("squirrel-girl")]
[ManualRoute("GET", "/repositories/{id}/issues/{number}")]
public Task Get(long repositoryId, int number)
{
return ApiConnection.Get(ApiUrls.Issue(repositoryId, number), null, AcceptHeaders.ReactionsPreview);
}
///
/// 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
///
[ManualRoute("GET", "/issues")]
public Task> 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
///
[ManualRoute("GET", "/issues")]
public Task> 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
[ManualRoute("GET", "/issues")]
public Task> 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
[Preview("squirrel-girl")]
[ManualRoute("GET", "/issues")]
public Task> GetAllForCurrent(IssueRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(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
///
[ManualRoute("GET", "/user/issues")]
public Task> GetAllForOwnedAndMemberRepositories()
{
return GetAllForOwnedAndMemberRepositories(ApiOptions.None);
}
///
/// Gets all open issues assigned to the authenticated user across owned and member repositories for the
/// authenticated user.
///
/// Options for changing the API response
///
/// Issues are sorted by the create date descending.
/// http://developer.github.com/v3/issues/#list-issues
///
[ManualRoute("GET", "/user/issues")]
public Task> 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
[ManualRoute("GET", "/user/issues")]
public Task> 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
[Preview("squirrel-girl")]
[ManualRoute("GET", "/user/issues")]
public Task> GetAllForOwnedAndMemberRepositories(IssueRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(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
[ManualRoute("GET", "/orgs/{org}/issues")]
public Task> 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
[ManualRoute("GET", "/orgs/{org}/issues")]
public Task> 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
[ManualRoute("GET", "/orgs/{org}/issues")]
public Task> 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
[Preview("squirrel-girl")]
[ManualRoute("GET", "/orgs/{org}/issues")]
public Task> GetAllForOrganization(string organization, IssueRequest request, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(organization, nameof(organization));
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(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
[ManualRoute("GET", "/repos/{owner}/{repo}/issues")]
public Task> GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return GetAllForRepository(owner, name, new RepositoryIssueRequest());
}
///
/// 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
[ManualRoute("GET", "/repositories/{id}/issues")]
public Task> GetAllForRepository(long repositoryId)
{
return GetAllForRepository(repositoryId, new RepositoryIssueRequest());
}
///
/// 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
[ManualRoute("GET", "/repos/{owner}/{repo}/issues")]
public Task> 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
[ManualRoute("GET", "/repositories/{id}/issues")]
public Task> 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
[ManualRoute("GET", "/repos/{owner}/{repo}/issues")]
public Task> 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
[ManualRoute("GET", "/repositories/{id}/issues")]
public Task> 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
[Preview("squirrel-girl")]
[ManualRoute("GET", "/repos/{owner}/{repo}/issues")]
public Task> 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 ApiConnection.GetAll(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
[Preview("squirrel-girl")]
[ManualRoute("GET", "/repositories/{id}/issues")]
public Task> GetAllForRepository(long repositoryId, RepositoryIssueRequest request, ApiOptions options)
{
Ensure.ArgumentNotNull(request, nameof(request));
Ensure.ArgumentNotNull(options, nameof(options));
return ApiConnection.GetAll(ApiUrls.Issues(repositoryId), request.ToParametersDictionary(), AcceptHeaders.ReactionsPreview, 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
[ManualRoute("POST", "/repos/{owner}/{repo}/issues")]
public Task Create(string owner, string name, NewIssue newIssue)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(newIssue, nameof(newIssue));
return ApiConnection.Post(ApiUrls.Issues(owner, name), newIssue);
}
///
/// 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
[ManualRoute("POST", "/repositories/{id}/issues")]
public Task Create(long repositoryId, NewIssue newIssue)
{
Ensure.ArgumentNotNull(newIssue, nameof(newIssue));
return ApiConnection.Post(ApiUrls.Issues(repositoryId), newIssue);
}
///
/// Updates an issue for the specified repository. Issue owners and users with push access can edit an issue.
///
/// https://developer.github.com/v3/issues/#edit-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
///
[ManualRoute("PATCH", "/repos/{owner}/{repo}/issues/{issue_number}")]
public Task Update(string owner, string name, int number, IssueUpdate issueUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
Ensure.ArgumentNotNull(issueUpdate, nameof(issueUpdate));
return ApiConnection.Patch(ApiUrls.Issue(owner, name, number), issueUpdate);
}
///
/// Updates an issue for the specified repository. Any user with pull access to a repository can update an
/// issue.
///
/// http://developer.github.com/v3/issues/#edit-an-issue
/// The Id of the repository
/// The issue number
/// An instance describing the changes to make to the issue
///
[ManualRoute("PATCH", "/repositories/{id}/issues/{number}")]
public Task Update(long repositoryId, int number, IssueUpdate issueUpdate)
{
Ensure.ArgumentNotNull(issueUpdate, nameof(issueUpdate));
return ApiConnection.Patch(ApiUrls.Issue(repositoryId, number), issueUpdate);
}
///
/// 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
[ManualRoute("PUT", "/repos/{owner}/{repo}/issues/{issue_number}/lock")]
public Task Lock(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Put(ApiUrls.IssueLock(owner, name, number), new object());
}
///
/// 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
[ManualRoute("PUT", "/repositories/{id}/issues/{number}/lock")]
public Task Lock(long repositoryId, int number)
{
return ApiConnection.Put(ApiUrls.IssueLock(repositoryId, number), new object());
}
///
/// 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
[ManualRoute("DELETE", "/repos/{owner}/{repo}/issues/{issue_number}/lock")]
public Task Unlock(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
return ApiConnection.Delete(ApiUrls.IssueLock(owner, name, number));
}
///
/// 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
[ManualRoute("DELETE", "/repositories/{id}/issues/{number}/lock")]
public Task Unlock(long repositoryId, int number)
{
return ApiConnection.Delete(ApiUrls.IssueLock(repositoryId, number));
}
}
}