Implement RepositoryCommentsClient

This commit is contained in:
Will Froese
2014-02-27 20:29:27 -05:00
parent fb9d400cfb
commit 50f65370c4
4 changed files with 165 additions and 4 deletions

View File

@@ -39,9 +39,9 @@ namespace Octokit
/// <remarks>http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit</remarks> /// <remarks>http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit</remarks>
/// <param name="owner">The owner of the repository</param> /// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param> /// <param name="name">The name of the repository</param>
/// <param name="number">The commit id</param> /// <param name="number">The sha of the commit</param>
/// <returns></returns> /// <returns></returns>
Task<IReadOnlyList<CommitComment>> GetForCommit(string owner, string name, int number); Task<IReadOnlyList<CommitComment>> GetForCommit(string owner, string name, string sha);
/// <summary> /// <summary>
/// Creates a new Commit Comment for a specified Issue. /// Creates a new Commit Comment for a specified Issue.
@@ -49,10 +49,10 @@ namespace Octokit
/// <remarks>http://developer.github.com/v3/repos/comments/#create-a-commit-comment</remarks> /// <remarks>http://developer.github.com/v3/repos/comments/#create-a-commit-comment</remarks>
/// <param name="owner">The owner of the repository</param> /// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param> /// <param name="name">The name of the repository</param>
/// <param name="reference">The sha reference of commit</param> /// <param name="sha">The sha reference of commit</param>
/// <param name="newCommitComment">The new comment to add to the commit</param> /// <param name="newCommitComment">The new comment to add to the commit</param>
/// <returns></returns> /// <returns></returns>
Task<CommitComment> Create(string owner, string name, string reference, NewCommitComment newCommitComment); Task<CommitComment> Create(string owner, string name, string sha, NewCommitComment newCommitComment);
/// <summary> /// <summary>
/// Updates a specified Commit Comment. /// Updates a specified Commit Comment.

View File

@@ -0,0 +1,125 @@

using System.Collections.Generic;
using System.Threading.Tasks;
namespace Octokit
{
/// <summary>
/// A client for GitHub's Repository Comments API.
/// </summary>
/// <remarks>
/// See the <a href="http://developer.github.com/v3/repos/comments/">Repository Comments API documentation</a> for more information.
/// </remarks>
public class RepositoryCommentsClient : ApiClient, IRepositoryCommentsClient
{
/// <summary>
/// Instantiates a new GitHub Repository Comments API client.
/// </summary>
/// <param name="apiConnection">An API connection</param>
public RepositoryCommentsClient(IApiConnection apiConnection)
: base(apiConnection)
{
}
/// <summary>
/// Gets a single Repository Comment by number.
/// </summary>
/// <remarks>http://developer.github.com/v3/repos/comments/#get-a-single-commit-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
public Task<CommitComment> Get(string owner, string name, int number)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.Get<CommitComment>(ApiUrls.CommitComment(owner, name, number));
}
/// <summary>
/// Gets Commit Comments for a repository.
/// </summary>
/// <remarks>http://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public Task<IReadOnlyList<CommitComment>> GetForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
return ApiConnection.GetAll<CommitComment>(ApiUrls.CommitComments(owner, name));
}
/// <summary>
/// Gets Commit Comments for a specified Commit.
/// </summary>
/// <remarks>http://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The sha of the commit</param>
/// <returns></returns>
public Task<IReadOnlyList<CommitComment>> GetForCommit(string owner, string name, string sha)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNullOrEmptyString(sha, "sha");
return ApiConnection.GetAll<CommitComment>(ApiUrls.CommitComments(owner, name, sha));
}
/// <summary>
/// Creates a new Commit Comment for a specified Issue.
/// </summary>
/// <remarks>http://developer.github.com/v3/repos/comments/#create-a-commit-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="sha">The sha reference of commit</param>
/// <param name="newCommitComment">The new comment to add to the commit</param>
/// <returns></returns>
public Task<CommitComment> 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<CommitComment>(ApiUrls.CommitComments(owner, name, sha), newCommitComment);
}
/// <summary>
/// Updates a specified Commit Comment.
/// </summary>
/// <remarks>http://developer.github.com/v3/repos/comments/#update-a-commit-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment number</param>
/// <param name="commentUpdate">The modified comment</param>
/// <returns></returns>
public Task<CommitComment> Update(string owner, string name, int number, string commentUpdate)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
return ApiConnection.Patch<CommitComment>(ApiUrls.CommitComment(owner, name, number), new BodyWrapper(commentUpdate));
}
/// <summary>
/// Deletes the specified Commit Comment
/// </summary>
/// <remarks>http://developer.github.com/v3/repos/comments/#delete-a-commit-comment</remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment id</param>
/// <returns></returns>
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));
}
}
}

View File

@@ -274,6 +274,41 @@ namespace Octokit
return "repos/{0}/{1}/issues/comments/{2}".FormatUri(owner, name, number); return "repos/{0}/{1}/issues/comments/{2}".FormatUri(owner, name, number);
} }
/// <summary>
/// Returns the <see cref="Uri"/> for the specified comment.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="number">The comment number</param>
/// <returns></returns>
public static Uri CommitComment(string owner, string name, int number)
{
return "repos/{0}/{1}/comments/{2}".FormatUri(owner, name, number);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the comments of a specified commit.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="sha">The sha of the commit</param>
/// <returns></returns>
public static Uri CommitComments(string owner, string name, string sha)
{
return "repos/{0}/{1}/commits/{2}/comments".FormatUri(owner, name, sha);
}
/// <summary>
/// Returns the <see cref="Uri"/> for the comments of a specified commit.
/// </summary>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <returns></returns>
public static Uri CommitComments(string owner, string name)
{
return "repos/{0}/{1}/comments".FormatUri(owner, name);
}
/// <summary> /// <summary>
/// Returns the <see cref="Uri"/> that returns all of the assignees to which issues may be assigned. /// Returns the <see cref="Uri"/> that returns all of the assignees to which issues may be assigned.
/// </summary> /// </summary>

View File

@@ -54,6 +54,7 @@
<Link>Properties\SolutionInfo.cs</Link> <Link>Properties\SolutionInfo.cs</Link>
</Compile> </Compile>
<Compile Include="Clients\ActivitiesClient.cs" /> <Compile Include="Clients\ActivitiesClient.cs" />
<Compile Include="Clients\RepositoryCommentsClient.cs" />
<Compile Include="Clients\IRepositoryCommentsClient.cs" /> <Compile Include="Clients\IRepositoryCommentsClient.cs" />
<Compile Include="Clients\FeedsClient.cs" /> <Compile Include="Clients\FeedsClient.cs" />
<Compile Include="Clients\IFeedsClient.cs" /> <Compile Include="Clients\IFeedsClient.cs" />