diff --git a/Octokit/Clients/IRepositoryCommentsClient.cs b/Octokit/Clients/IRepositoryCommentsClient.cs index ff4257c9..2ffa9649 100644 --- a/Octokit/Clients/IRepositoryCommentsClient.cs +++ b/Octokit/Clients/IRepositoryCommentsClient.cs @@ -39,9 +39,9 @@ namespace Octokit /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit /// The owner of the repository /// The name of the repository - /// The commit id + /// The sha of the commit /// - Task> GetForCommit(string owner, string name, int number); + Task> GetForCommit(string owner, string name, string sha); /// /// Creates a new Commit Comment for a specified Issue. @@ -49,10 +49,10 @@ namespace Octokit /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment /// The owner of the repository /// The name of the repository - /// The sha reference of commit + /// The sha reference of commit /// The new comment to add to the commit /// - Task Create(string owner, string name, string reference, NewCommitComment newCommitComment); + Task Create(string owner, string name, string sha, NewCommitComment newCommitComment); /// /// Updates a specified Commit Comment. diff --git a/Octokit/Clients/RepositoryCommentsClient.cs b/Octokit/Clients/RepositoryCommentsClient.cs new file mode 100644 index 00000000..b5138b0b --- /dev/null +++ b/Octokit/Clients/RepositoryCommentsClient.cs @@ -0,0 +1,125 @@ + +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Octokit +{ + /// + /// A client for GitHub's Repository Comments API. + /// + /// + /// See the Repository Comments API documentation for more information. + /// + public class RepositoryCommentsClient : ApiClient, IRepositoryCommentsClient + { + /// + /// Instantiates a new GitHub Repository Comments API client. + /// + /// An API connection + public RepositoryCommentsClient(IApiConnection apiConnection) + : base(apiConnection) + { + } + + /// + /// Gets a single Repository Comment by number. + /// + /// http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// + public Task Get(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.Get(ApiUrls.CommitComment(owner, name, number)); + } + + /// + /// Gets Commit Comments for a repository. + /// + /// http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository + /// The owner of the repository + /// The name of the repository + /// + public Task> GetForRepository(string owner, string name) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name)); + } + + /// + /// Gets Commit Comments for a specified Commit. + /// + /// http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit + /// The owner of the repository + /// The name of the repository + /// The sha of the commit + /// + public Task> GetForCommit(string owner, string name, string sha) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + + return ApiConnection.GetAll(ApiUrls.CommitComments(owner, name, sha)); + } + + /// + /// Creates a new Commit Comment for a specified Issue. + /// + /// http://developer.github.com/v3/repos/comments/#create-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The sha reference of commit + /// The new comment to add to the commit + /// + public Task Create(string owner, string name, string sha, NewCommitComment newCommitComment) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNullOrEmptyString(sha, "sha"); + Ensure.ArgumentNotNull(newCommitComment, "newCommitComment"); + + return ApiConnection.Post(ApiUrls.CommitComments(owner, name, sha), newCommitComment); + } + + /// + /// Updates a specified Commit Comment. + /// + /// http://developer.github.com/v3/repos/comments/#update-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment number + /// The modified comment + /// + public Task Update(string owner, string name, int number, string commentUpdate) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + Ensure.ArgumentNotNull(commentUpdate, "commentUpdate"); + + return ApiConnection.Patch(ApiUrls.CommitComment(owner, name, number), new BodyWrapper(commentUpdate)); + } + + /// + /// Deletes the specified Commit Comment + /// + /// http://developer.github.com/v3/repos/comments/#delete-a-commit-comment + /// The owner of the repository + /// The name of the repository + /// The comment id + /// + public Task Delete(string owner, string name, int number) + { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + + return ApiConnection.Delete(ApiUrls.CommitComment(owner, name, number)); + } + } +} diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index d7dd4a54..6a650ec6 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -274,6 +274,41 @@ namespace Octokit return "repos/{0}/{1}/issues/comments/{2}".FormatUri(owner, name, number); } + /// + /// Returns the for the specified comment. + /// + /// The owner of the repository + /// The name of the repository + /// The comment number + /// + public static Uri CommitComment(string owner, string name, int number) + { + return "repos/{0}/{1}/comments/{2}".FormatUri(owner, name, number); + } + + /// + /// Returns the for the comments of a specified commit. + /// + /// The owner of the repository + /// The name of the repository + /// The sha of the commit + /// + public static Uri CommitComments(string owner, string name, string sha) + { + return "repos/{0}/{1}/commits/{2}/comments".FormatUri(owner, name, sha); + } + + /// + /// Returns the for the comments of a specified commit. + /// + /// The owner of the repository + /// The name of the repository + /// + public static Uri CommitComments(string owner, string name) + { + return "repos/{0}/{1}/comments".FormatUri(owner, name); + } + /// /// Returns the that returns all of the assignees to which issues may be assigned. /// diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 8a29a0e0..669d29a1 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -54,6 +54,7 @@ Properties\SolutionInfo.cs +