using System.Collections.Generic; using System.Threading.Tasks; namespace Octokit { /// /// A client for GitHub's Issue Assignees API. /// /// /// See the Issue Assignees API documentation for more information. /// public class AssigneesClient : ApiClient, IAssigneesClient { /// /// Instantiates a new GitHub Issue Assignees API client. /// /// An API connection public AssigneesClient(IApiConnection apiConnection) : base(apiConnection) { } /// /// Gets all the available assignees (owner + collaborators) to which issues may be assigned. /// /// The owner of the repository /// The name of the repository [ManualRoute("GET", "/repos/{owner}/{repo}/assignees")] public Task> GetAllForRepository(string owner, string name) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); return GetAllForRepository(owner, name, ApiOptions.None); } /// /// Gets all the available assignees (owner + collaborators) to which issues may be assigned. /// /// The Id of the repository [ManualRoute("GET", "/repositories/{id}/assignees")] public Task> GetAllForRepository(long repositoryId) { return GetAllForRepository(repositoryId, ApiOptions.None); } /// /// Gets all the available assignees (owner + collaborators) to which issues may be assigned. /// /// The owner of the repository /// The name of the repository /// The options to change API's response. [ManualRoute("GET", "/repos/{owner}/{repo}/assignees")] public Task> GetAllForRepository(string owner, string name, ApiOptions options) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(options, nameof(options)); var endpoint = ApiUrls.Assignees(owner, name); return ApiConnection.GetAll(endpoint, null, AcceptHeaders.StableVersion, options); } /// /// Gets all the available assignees (owner + collaborators) to which issues may be assigned. /// /// The Id of the repository /// The options to change API's response. [ManualRoute("GET", "/repositories/{id}/assignees")] public Task> GetAllForRepository(long repositoryId, ApiOptions options) { Ensure.ArgumentNotNull(options, nameof(options)); var endpoint = ApiUrls.Assignees(repositoryId); return ApiConnection.GetAll(endpoint, null, AcceptHeaders.StableVersion, options); } /// /// Checks to see if a user is an assignee for a repository. /// /// The owner of the repository /// The name of the repository /// Username of the prospective assignee [ManualRoute("GET", "/repos/{owner}/{repo}/assignees/{username}")] public async Task CheckAssignee(string owner, string name, string assignee) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNullOrEmptyString(assignee, nameof(assignee)); try { var response = await Connection.Get(ApiUrls.CheckAssignee(owner, name, assignee), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) { return false; } } /// /// Add assignees to a specified Issue. /// /// The owner of the repository /// The name of the repository /// The issue number /// List of names of assignees to add /// [ManualRoute("POST", "/repos/{owner}/{repo}/issues/{issue_number}/assignees")] public Task AddAssignees(string owner, string name, int number, AssigneesUpdate assignees) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(assignees, nameof(assignees)); return ApiConnection.Post(ApiUrls.IssueAssignees(owner, name, number), assignees); } /// /// Remove assignees from a specified Issue. /// /// The owner of the repository /// The name of the repository /// The issue number /// List of assignees to remove /// [ManualRoute("DELETE", "/repos/{owner}/{repo}/issues/{issue_number}/assignees")] public Task RemoveAssignees(string owner, string name, int number, AssigneesUpdate assignees) { Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); Ensure.ArgumentNotNull(assignees, nameof(assignees)); return ApiConnection.Delete(ApiUrls.IssueAssignees(owner, name, number), assignees); } /// /// Checks to see if a user is an assignee for a repository. /// /// The Id of the repository /// Username of the prospective assignee [ManualRoute("GET", "/repositories/{id}/assignees/{username}")] public async Task CheckAssignee(long repositoryId, string assignee) { Ensure.ArgumentNotNullOrEmptyString(assignee, nameof(assignee)); try { var response = await Connection.Get(ApiUrls.CheckAssignee(repositoryId, assignee), null, null).ConfigureAwait(false); return response.HttpResponse.IsTrue(); } catch (NotFoundException) { return false; } } } }