Files
octokit.net/Octokit/Clients/IssueCommentsClient.cs
Martin Scholz 72e30a7f90 Add reactions to issue, commit comment and review payload (#1405)
* add reactions to issue response payload

* add reactions to commit comment payload

* add reactions to review comment payload

* create tests for issue client

* tests for commitcomment client

* tests for pull request review comment

* change observable tests

* simplify strings

* remove unnecessary clients

* change integration tests to retrieve all reaction types

* create integration test for issue comment client

* fix merge conflicts

* fix merge conflicts

* gets tests passing again

* fix some reaction integration tests

* Fixup unit tests wth preview accepts header
Also applied preview header to a couple of repositoryId based calls that were added by another PR

* Fixup unit tests wth preview accepts header
Also applied preview header to a couple of repositoryId based calls that were added by another PR

* Rework reaction payload tests for IssueComments to handle Get, GetAllForIssue and GetAllForRepository calls

* [WIP] reaction payload tests

* Rework reaction payload tests for IssueComments to handle Get, GetAllForIssue and GetAllForRepository calls

* Rework reaction payload tests for Issues client

* Rework reaction payload tests for PullRequestReviews client

* Rework reaction payload tests for CommitComments client

* Revert "[WIP] reaction payload tests"

This reverts commit a6179b0f21a3ddfe36bfd3ae5eafae0e69b52252.
2016-07-08 20:29:08 +10:00

247 lines
12 KiB
C#

using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Issue Comments API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/issues/comments/">Issue Comments API documentation</a> for more information.
/// </remarks>
public class IssueCommentsClient : ApiClient, IIssueCommentsClient
{
/// <summary>
/// Instantiates a new GitHub Issue Comments API client.
/// </summary>
/// <param name="apiConnection">An API connection</param>
public IssueCommentsClient(IApiConnection apiConnection) : base(apiConnection)
{
}
/// <summary>
/// Gets a single Issue Comment by id.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#get-a-single-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="id">The issue comment id</param>
public Task<IssueComment> Get(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.Get<IssueComment>(ApiUrls.IssueComment(owner, name, id), null, AcceptHeaders.ReactionsPreview);
}
/// <summary>
/// Gets a single Issue Comment by id.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#get-a-single-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="id">The issue comment id</param>
public Task<IssueComment> Get(int repositoryId, int id)
{
return ApiConnection.Get<IssueComment>(ApiUrls.IssueComment(repositoryId, id), null, AcceptHeaders.ReactionsPreview);
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
public Task<IReadOnlyList<IssueComment>> GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllForRepository(owner, name, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The ID of the repository</param>
public Task<IReadOnlyList<IssueComment>> GetAllForRepository(int repositoryId)
{
return GetAllForRepository(repositoryId, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="options">Options for changing the API response</param>
public Task<IReadOnlyList<IssueComment>> GetAllForRepository(string owner, string name, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<IssueComment>(ApiUrls.IssueComments(owner, name), null, AcceptHeaders.ReactionsPreview, options);
}
/// <summary>
/// Gets Issue Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-in-a-repository</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="options">Options for changing the API response</param>
public Task<IReadOnlyList<IssueComment>> GetAllForRepository(int repositoryId, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<IssueComment>(ApiUrls.IssueComments(repositoryId), null, AcceptHeaders.ReactionsPreview, options);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The issue number</param>
public Task<IReadOnlyList<IssueComment>> GetAllForIssue(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return GetAllForIssue(owner, name, number, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The issue number</param>
public Task<IReadOnlyList<IssueComment>> GetAllForIssue(int repositoryId, int number)
{
return GetAllForIssue(repositoryId, number, ApiOptions.None);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="options">Options for changing the API response</param>
public Task<IReadOnlyList<IssueComment>> GetAllForIssue(string owner, string name, int number, ApiOptions options)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<IssueComment>(ApiUrls.IssueComments(owner, name, number), null, AcceptHeaders.ReactionsPreview, options);
}
/// <summary>
/// Gets Issue Comments for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#list-comments-on-an-issue</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The issue number</param>
/// <param name="options">Options for changing the API response</param>
public Task<IReadOnlyList<IssueComment>> GetAllForIssue(int repositoryId, int number, ApiOptions options)
{
Ensure.ArgumentNotNull(options, "options");
return ApiConnection.GetAll<IssueComment>(ApiUrls.IssueComments(repositoryId, number), null, AcceptHeaders.ReactionsPreview, options);
}
/// <summary>
/// Creates a new Issue Comment for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#create-a-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The number of the issue</param>
/// <param name="newComment">The new comment to add to the issue</param>
public Task<IssueComment> Create(string owner, string name, int number, string newComment)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(newComment, "newComment");
return ApiConnection.Post<IssueComment>(ApiUrls.IssueComments(owner, name, number), new BodyWrapper(newComment));
}
/// <summary>
/// Creates a new Issue Comment for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#create-a-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="number">The number of the issue</param>
/// <param name="newComment">The new comment to add to the issue</param>
public Task<IssueComment> Create(int repositoryId, int number, string newComment)
{
Ensure.ArgumentNotNull(newComment, "newComment");
return ApiConnection.Post<IssueComment>(ApiUrls.IssueComments(repositoryId, number), new BodyWrapper(newComment));
}
/// <summary>
/// Updates a specified Issue Comment.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#edit-a-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="id">The comment id</param>
/// <param name="commentUpdate">The modified comment</param>
public Task<IssueComment> Update(string owner, string name, int id, string commentUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
return ApiConnection.Patch<IssueComment>(ApiUrls.IssueComment(owner, name, id), new BodyWrapper(commentUpdate));
}
/// <summary>
/// Updates a specified Issue Comment.
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#edit-a-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="id">The comment id</param>
/// <param name="commentUpdate">The modified comment</param>
public Task<IssueComment> Update(int repositoryId, int id, string commentUpdate)
{
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
return ApiConnection.Patch<IssueComment>(ApiUrls.IssueComment(repositoryId, id), new BodyWrapper(commentUpdate));
}
/// <summary>
/// Deletes the specified Issue Comment
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#delete-a-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="id">The comment id</param>
public Task Delete(string owner, string name, int id)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.Delete(ApiUrls.IssueComment(owner, name, id));
}
/// <summary>
/// Deletes the specified Issue Comment
/// </summary>
/// <remarks>http://developer.github.com/v3/issues/comments/#delete-a-comment</remarks>
/// <param name="repositoryId">The ID of the repository</param>
/// <param name="id">The comment id</param>
public Task Delete(int repositoryId, int id)
{
return ApiConnection.Delete(ApiUrls.IssueComment(repositoryId, id));
}
}
}