mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-12 06:00:38 +00:00
Merge pull request #148 from pltaylor/issue-comments-uri
Issue comments uri
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public interface IObservableIssueCommentsClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a single Issue Comment by number.
|
||||
/// </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="number">The issue number</param>
|
||||
/// <returns></returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
|
||||
Justification = "Method makes a network request")]
|
||||
IObservable<IssueComment> Get(string owner, string name, int number);
|
||||
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
IObservable<IssueComment> GetForRepository(string owner, string name);
|
||||
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
IObservable<IssueComment> GetForIssue(string owner, string name, int number);
|
||||
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
IObservable<IssueComment> Create(string owner, string name, int number, string 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="number">The comment number</param>
|
||||
/// <param name="commentUpdate">The modified comment</param>
|
||||
/// <returns></returns>
|
||||
IObservable<IssueComment> Update(string owner, string name, int number, string commentUpdate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using Octokit.Reactive.Internal;
|
||||
|
||||
namespace Octokit.Reactive
|
||||
{
|
||||
public class ObservableIssueCommentsClient : IObservableIssueCommentsClient
|
||||
{
|
||||
readonly IIssueCommentsClient _client;
|
||||
readonly IConnection _connection;
|
||||
|
||||
public ObservableIssueCommentsClient(IGitHubClient client)
|
||||
{
|
||||
Ensure.ArgumentNotNull(client, "client");
|
||||
|
||||
_client = client.Issue.Comment;
|
||||
_connection = client.Connection;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single Issue Comment by number.
|
||||
/// </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="number">The issue comment number</param>
|
||||
/// <returns>The <see cref="IssueComment"/>s for the specified Issue Comment.</returns>
|
||||
public IObservable<IssueComment> Get(string owner, string name, int number)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _client.Get(owner, name, number).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of the Issue Comments in a specified 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>
|
||||
/// <returns>The list of <see cref="IssueComment"/>s for the specified Repository.</returns>
|
||||
public IObservable<IssueComment> GetForRepository(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(owner, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of the 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>
|
||||
/// <returns>The list of <see cref="IssueComment"/>s for the specified Issue.</returns>
|
||||
public IObservable<IssueComment> GetForIssue(string owner, string name, int number)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _connection.GetAndFlattenAllPages<IssueComment>(ApiUrls.IssueComments(owner, name, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Issue Comment in the 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 issue number</param>
|
||||
/// <param name="newComment">The text of the new comment</param>
|
||||
/// <returns>The <see cref="IssueComment"/>s for that was just created.</returns>
|
||||
public IObservable<IssueComment> Create(string owner, string name, int number, string newComment)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(newComment, "newComment");
|
||||
|
||||
return _client.Create(owner, name, number, newComment).ToObservable();
|
||||
}
|
||||
|
||||
/// <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="number">The issue number</param>
|
||||
/// <param name="commentUpdate">The text of the updated comment</param>
|
||||
/// <returns>The <see cref="IssueComment"/>s for that was just updated.</returns>
|
||||
public IObservable<IssueComment> Update(string owner, string name, int number, string commentUpdate)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
|
||||
|
||||
return _client.Update(owner, name, number, commentUpdate).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ namespace Octokit.Reactive
|
||||
|
||||
public IObservableAssigneesClient Assignee { get; private set; }
|
||||
public IObservableMilestonesClient Milestone { get; private set; }
|
||||
public IObservableIssueCommentsClient Comments { get; private set; }
|
||||
|
||||
public ObservableIssuesClient(IGitHubClient client)
|
||||
{
|
||||
@@ -22,6 +23,7 @@ namespace Octokit.Reactive
|
||||
_connection = client.Connection;
|
||||
Assignee = new ObservableAssigneesClient(client);
|
||||
Milestone = new ObservableMilestonesClient(client);
|
||||
Comments = new ObservableIssueCommentsClient(client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -82,9 +82,11 @@
|
||||
<Compile Include="Clients\IObservableMilestonesClient.cs" />
|
||||
<Compile Include="Clients\ObservableIssuesClient.cs" />
|
||||
<Compile Include="Clients\ObservableMilestonesClient.cs" />
|
||||
<Compile Include="Clients\IObservableIssueCommentsClient.cs" />
|
||||
<Compile Include="Clients\ObservableAssigneesClient.cs" />
|
||||
<Compile Include="Clients\IObservableCommitStatusClient.cs" />
|
||||
<Compile Include="Clients\ObservableCommitStatusClient.cs" />
|
||||
<Compile Include="Clients\ObservableIssueCommentsClient.cs" />
|
||||
<Compile Include="Clients\ObservableNotificationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableAuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\ObservableMiscellaneousClient.cs" />
|
||||
@@ -133,4 +135,4 @@
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit;
|
||||
using Octokit.Internal;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
public class IssueCommentsClientTests
|
||||
{
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
client.Get("fake", "repo", 42);
|
||||
|
||||
connection.Received().Get<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/comments/42"),
|
||||
null);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new IssueCommentsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("", "name", 1));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "", 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TheGetForRepositoryMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
client.GetForRepository("fake", "repo");
|
||||
|
||||
connection.Received().GetAll<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/comments"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForRepository(null, "name"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForRepository("", "name"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForRepository("owner", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForRepository("owner", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetForIssueMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
client.GetForIssue("fake", "repo", 3);
|
||||
|
||||
connection.Received().GetAll<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/3/comments"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForIssue(null, "name", 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForIssue("", "name", 1));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForIssue("owner", null, 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForIssue("owner", "", 1));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
const string newComment = "some title";
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
client.Create("fake", "repo", 1, newComment);
|
||||
|
||||
connection.Received().Post<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/1/comments"), newComment);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", 1, "title"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", 1, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, 1, "x"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", 1, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", 1, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUpdateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
const string issueCommentUpdate = "Worthwhile update";
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
client.Update("fake", "repo", 42, issueCommentUpdate);
|
||||
|
||||
connection.Received().Patch<IssueComment>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/comments/42"),
|
||||
issueCommentUpdate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssueCommentsClient(connection);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Update(null, "name", 42, "title"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Update("", "name", 42, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Update("owner", null, 42, "x"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Update("owner", "", 42, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Update("owner", "name", 42, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgument()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new IssueCommentsClient(null));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CanDeserializeIssueComment()
|
||||
{
|
||||
const string issueResponseJson =
|
||||
"{\"id\": 1," +
|
||||
"\"url\": \"https://api.github.com/repos/octocat/Hello-World/issues/comments/1\"," +
|
||||
"\"html_url\": \"https://github.com/octocat/Hello-World/issues/1347#issuecomment-1\"," +
|
||||
"\"body\": \"Me too\"," +
|
||||
"\"user\": {" +
|
||||
"\"login\": \"octocat\"," +
|
||||
"\"id\": 1," +
|
||||
"\"avatar_url\": \"https://github.com/images/error/octocat_happy.gif\"," +
|
||||
"\"gravatar_id\": \"somehexcode\"," +
|
||||
"\"url\": \"https://api.github.com/users/octocat\"" +
|
||||
"}," +
|
||||
"\"created_at\": \"2011-04-14T16:00:49Z\"," +
|
||||
"\"updated_at\": \"2011-04-14T16:00:49Z\"" +
|
||||
"}";
|
||||
var response = new ApiResponse<IssueComment>
|
||||
{
|
||||
Body = issueResponseJson,
|
||||
ContentType = "application/json"
|
||||
};
|
||||
var jsonPipeline = new JsonHttpPipeline();
|
||||
|
||||
jsonPipeline.DeserializeResponse(response);
|
||||
|
||||
Assert.NotNull(response.BodyAsObject);
|
||||
Assert.Equal(issueResponseJson, response.Body);
|
||||
Assert.Equal(1, response.BodyAsObject.Id);
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@
|
||||
<Compile Include="Clients\GitDatabaseClientTests.cs" />
|
||||
<Compile Include="Clients\TagsClientTests.cs" />
|
||||
<Compile Include="Clients\IssuesEventsClientTests.cs" />
|
||||
<Compile Include="Clients\IssueCommentsClientTests.cs" />
|
||||
<Compile Include="Clients\MilestonesClientTests.cs" />
|
||||
<Compile Include="Clients\IssuesClientTests.cs" />
|
||||
<Compile Include="Clients\NotificationsClientTests.cs" />
|
||||
@@ -109,6 +110,7 @@
|
||||
<Compile Include="Helpers\StringExtensionsTests.cs" />
|
||||
<Compile Include="Clients\RepositoriesClientTests.cs" />
|
||||
<Compile Include="Reactive\AuthorizationExtensionsTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssueCommentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
using System;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableIssueCommentsClientTests
|
||||
{
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsFromClientIssueComment()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
client.Get("fake", "repo", 42);
|
||||
|
||||
gitHubClient.Issue.Comment.Received().Get("fake", "repo", 42);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableIssueCommentsClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("", "name", 1));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "", 1));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TheGetForRepositoryMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
client.GetForRepository("fake", "repo");
|
||||
|
||||
gitHubClient.Issue.Comment.Received().GetForRepository("fake", "repo");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForRepository(null, "name"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForRepository("", "name"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForRepository("owner", null));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForRepository("owner", ""));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetForIssueMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
client.GetForIssue("fake", "repo", 3);
|
||||
|
||||
gitHubClient.Issue.Comment.Received().GetForIssue("fake", "repo", 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForIssue(null, "name", 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForIssue("", "name", 1));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForIssue("owner", null, 1));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.GetForIssue("owner", "", 1));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
const string newComment = "some title";
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
client.Create("fake", "repo", 1, newComment);
|
||||
|
||||
gitHubClient.Issue.Comment.Received().Create("fake", "repo", 1, newComment);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", 1, "title"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", 1, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, 1, "x"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", 1, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", 1, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheUpdateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
const string issueCommentUpdate = "Worthwhile update";
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
client.Update("fake", "repo", 42, issueCommentUpdate);
|
||||
|
||||
gitHubClient.Issue.Comment.Received().Update("fake", "repo", 42, issueCommentUpdate);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableIssueCommentsClient(gitHubClient);
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Update(null, "name", 42, "title"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Update("", "name", 42, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Update("owner", null, 42, "x"));
|
||||
await AssertEx.Throws<ArgumentException>(async () => await client.Update("owner", "", 42, "x"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Update("owner", "name", 42, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgument()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ObservableIssueCommentsClient(null));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public interface IIssueCommentsClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a single Issue Comment by number.
|
||||
/// </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="number">The issue number</param>
|
||||
/// <returns></returns>
|
||||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get",
|
||||
Justification = "Method makes a network request")]
|
||||
Task<IssueComment> Get(string owner, string name, int number);
|
||||
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<IssueComment>> GetForRepository(string owner, string name);
|
||||
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<IssueComment>> GetForIssue(string owner, string name, int number);
|
||||
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
Task<IssueComment> Create(string owner, string name, int number, string 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="number">The comment number</param>
|
||||
/// <param name="commentUpdate">The modified comment</param>
|
||||
/// <returns></returns>
|
||||
Task<IssueComment> Update(string owner, string name, int number, string commentUpdate);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,11 @@ namespace Octokit
|
||||
/// </summary>
|
||||
IMilestonesClient Milestone { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Client for managing comments.
|
||||
/// </summary>
|
||||
IIssueCommentsClient Comment { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single Issue by number.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public class IssueCommentsClient : ApiClient, IIssueCommentsClient
|
||||
{
|
||||
public IssueCommentsClient(IApiConnection apiConnection) : base(apiConnection)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single Issue Comment by number.
|
||||
/// </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="number">The issue comment number</param>
|
||||
/// <returns>The <see cref="IssueComment"/>s for the specified Issue Comment.</returns>
|
||||
public Task<IssueComment> Get(string owner, string name, int number)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return ApiConnection.Get<IssueComment>(ApiUrls.IssueComment(owner, name, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of the Issue Comments in a specified 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>
|
||||
/// <returns>The list of <see cref="IssueComment"/>s for the specified Repository.</returns>
|
||||
public Task<IReadOnlyList<IssueComment>> GetForRepository(string owner, string name)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return ApiConnection.GetAll<IssueComment>(ApiUrls.IssueComments(owner, name));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a list of the 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>
|
||||
/// <returns>The list of <see cref="IssueComment"/>s for the specified Issue.</returns>
|
||||
public Task<IReadOnlyList<IssueComment>> GetForIssue(string owner, string name, int number)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return ApiConnection.GetAll<IssueComment>(ApiUrls.IssueComments(owner, name, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new Issue Comment in the 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 issue number</param>
|
||||
/// <param name="newComment">The text of the new comment</param>
|
||||
/// <returns>The <see cref="IssueComment"/>s for that was just created.</returns>
|
||||
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), 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="number">The issue number</param>
|
||||
/// <param name="commentUpdate">The text of the updated comment</param>
|
||||
/// <returns>The <see cref="IssueComment"/>s for that was just updated.</returns>
|
||||
public Task<IssueComment> Update(string owner, string name, int number, string commentUpdate)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(commentUpdate, "commentUpdate");
|
||||
|
||||
return ApiConnection.Patch<IssueComment>(ApiUrls.IssueComment(owner, name, number), commentUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,13 @@ namespace Octokit
|
||||
Assignee = new AssigneesClient(apiConnection);
|
||||
Events = new IssuesEventsClient(apiConnection);
|
||||
Milestone = new MilestonesClient(apiConnection);
|
||||
Comment = new IssueCommentsClient(apiConnection);
|
||||
}
|
||||
|
||||
public IAssigneesClient Assignee { get; private set; }
|
||||
public IIssuesEventsClient Events { get; private set; }
|
||||
public IMilestonesClient Milestone { get; private set; }
|
||||
public IIssueCommentsClient Comment { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a single Issue by number./// </summary>
|
||||
|
||||
@@ -188,6 +188,41 @@ namespace Octokit
|
||||
return "repos/{0}/{1}/issues/{2}".FormatUri(owner, name, number);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for the comments for all issues in a specific repo.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <returns></returns>
|
||||
public static Uri IssueComments(string owner, string name)
|
||||
{
|
||||
return "repos/{0}/{1}/issues/comments".FormatUri(owner, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> for the comments of a specified issue.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
/// <returns></returns>
|
||||
public static Uri IssueComments(string owner, string name, int number)
|
||||
{
|
||||
return "repos/{0}/{1}/issues/{2}/comments".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 IssueComment(string owner, string name, int number)
|
||||
{
|
||||
return "repos/{0}/{1}/issues/comments/{2}".FormatUri(owner, name, number);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all of the assignees to which issues may be assigned.
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
public class IssueComment
|
||||
{
|
||||
/// <summary>
|
||||
/// The issue comment Id.
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL for this issue comment.
|
||||
/// </summary>
|
||||
public Uri Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The html URL for this issue comment.
|
||||
/// </summary>
|
||||
public Uri HtmlUrl { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Details about the issue comment.
|
||||
/// </summary>
|
||||
public string Body { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The date the issue comment was created.
|
||||
/// </summary>
|
||||
public DateTimeOffset CreatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The date the issue comment was last updated.
|
||||
/// </summary>
|
||||
public DateTimeOffset? UpdatedAt { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The user that created the issue comment.
|
||||
/// </summary>
|
||||
public User User { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,7 @@
|
||||
<Compile Include="Clients\IAuthorizationsClient.cs" />
|
||||
<Compile Include="Clients\ICommitStatusClient.cs" />
|
||||
<Compile Include="Clients\IGitDatabaseClient.cs" />
|
||||
<Compile Include="Clients\IIssueCommentsClient.cs" />
|
||||
<Compile Include="Clients\IIssuesClient.cs" />
|
||||
<Compile Include="Clients\IIssuesEventsClient.cs" />
|
||||
<Compile Include="Clients\IMilestonesClient.cs" />
|
||||
@@ -67,6 +68,7 @@
|
||||
<Compile Include="Clients\IReleasesClient.cs" />
|
||||
<Compile Include="Clients\IRepositoriesClient.cs" />
|
||||
<Compile Include="Clients\ISshKeysClient.cs" />
|
||||
<Compile Include="Clients\IssueCommentsClient.cs" />
|
||||
<Compile Include="Clients\IssuesClient.cs" />
|
||||
<Compile Include="Clients\ITagsClient.cs" />
|
||||
<Compile Include="Clients\IssuesEventsClient.cs" />
|
||||
@@ -156,6 +158,7 @@
|
||||
<Compile Include="Models\Response\GitTag.cs" />
|
||||
<Compile Include="Models\Response\EventInfo.cs" />
|
||||
<Compile Include="Models\Response\Issue.cs" />
|
||||
<Compile Include="Models\Response\IssueComment.cs" />
|
||||
<Compile Include="Models\Response\IssueEvent.cs" />
|
||||
<Compile Include="Models\Response\Label.cs" />
|
||||
<Compile Include="Models\Response\Milestone.cs" />
|
||||
|
||||
@@ -58,6 +58,8 @@
|
||||
<Compile Include="Clients\IIssuesEventsClient.cs" />
|
||||
<Compile Include="Clients\ICommitStatusClient.cs" />
|
||||
<Compile Include="Clients\IGitDatabaseClient.cs" />
|
||||
<Compile Include="Clients\IIssueCommentsClient.cs" />
|
||||
<Compile Include="Clients\IssueCommentsClient.cs" />
|
||||
<Compile Include="Clients\IssuesClient.cs" />
|
||||
<Compile Include="Clients\ITagsClient.cs" />
|
||||
<Compile Include="Clients\IssuesEventsClient.cs" />
|
||||
@@ -79,6 +81,7 @@
|
||||
<Compile Include="Models\Request\IssueRequest.cs" />
|
||||
<Compile Include="Models\Request\IssueUpdate.cs" />
|
||||
<Compile Include="Models\Response\IssueEvent.cs" />
|
||||
<Compile Include="Models\Response\IssueComment.cs" />
|
||||
<Compile Include="Models\Response\Label.cs" />
|
||||
<Compile Include="Models\Response\Milestone.cs" />
|
||||
<Compile Include="Models\Request\NewIssue.cs" />
|
||||
|
||||
Reference in New Issue
Block a user