mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
Merge pull request #316 from pmacn/issuelabels
Implemented missing methods for IssueLabels...
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using NSubstitute;
|
||||
using Octokit.Tests.Helpers;
|
||||
using Xunit;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Octokit.Tests.Clients
|
||||
{
|
||||
@@ -79,5 +80,127 @@ namespace Octokit.Tests.Clients
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "label"));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheAddToIssueMethod
|
||||
{
|
||||
readonly string[] labels = { "foo", "bar" };
|
||||
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssuesLabelsClient(connection);
|
||||
|
||||
client.AddToIssue("fake", "repo", 42, labels);
|
||||
|
||||
connection.Received().Post<IReadOnlyList<Label>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Arg.Any<string[]>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.AddToIssue(null, "name", 42, labels));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.AddToIssue("owner", null, 42, labels));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.AddToIssue("owner", "name", 42, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRemoveFromIssueMethod
|
||||
{
|
||||
[Fact]
|
||||
public void DeleteCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssuesLabelsClient(connection);
|
||||
|
||||
client.RemoveFromIssue("fake", "repo", 42, "label");
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels/label"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.RemoveFromIssue(null, "name", 42, "label"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.RemoveFromIssue("owner", null, 42, "label"));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.RemoveFromIssue("owner", "name", 42, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheReplaceForIssueMethod
|
||||
{
|
||||
readonly string[] labels = { "foo", "bar" };
|
||||
|
||||
[Fact]
|
||||
public void PutsToCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssuesLabelsClient(connection);
|
||||
|
||||
client.ReplaceAllForIssue("fake", "repo", 42, labels);
|
||||
|
||||
connection.Received().Put<IReadOnlyList<Label>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"), Arg.Any<string[]>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.ReplaceAllForIssue(null, "name", 42, labels));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.ReplaceAllForIssue("owner", null, 42, labels));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.ReplaceAllForIssue("owner", "name", 42, null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheRemoveAllFromIssueMethod
|
||||
{
|
||||
[Fact]
|
||||
public void DeletesCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssuesLabelsClient(connection);
|
||||
|
||||
client.RemoveAllFromIssue("fake", "repo", 42);
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.RemoveAllFromIssue(null, "name", 42));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.RemoveAllFromIssue("owner", null, 42));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetForMilestoneMethod
|
||||
{
|
||||
[Fact]
|
||||
public void GetsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new IssuesLabelsClient(connection);
|
||||
|
||||
client.GetForMilestone("fake", "repo", 42);
|
||||
|
||||
connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/milestones/42/labels"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new IssuesLabelsClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForMilestone(null, "name", 42));
|
||||
await AssertEx.Throws<ArgumentNullException>(async () => await client.GetForMilestone("owner", null, 42));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,5 +79,68 @@ namespace Octokit
|
||||
/// <param name="labelUpdate">The data for the label to be updated</param>
|
||||
/// <returns>The updated label</returns>
|
||||
Task<Label> Update(string owner, string repo, string name, LabelUpdate labelUpdate);
|
||||
|
||||
/// <summary>
|
||||
/// Adds a label to an issue
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#add-labels-to-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <param name="labels">The names of the labels to add</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<Label>> AddToIssue(string owner, string repo, int number, string[] labels);
|
||||
|
||||
/// <summary>
|
||||
/// Removes a label from an issue
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <param name="label">The name of the label to remove</param>
|
||||
/// <returns></returns>
|
||||
Task RemoveFromIssue(string owner, string repo, int number, string label);
|
||||
|
||||
/// <summary>
|
||||
/// Replaces all labels on the specified issues with the provided labels
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <param name="labels">The names of the labels to set</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<Label>> ReplaceAllForIssue(string owner, string repo, int number, string[] labels);
|
||||
|
||||
/// <summary>
|
||||
/// Removes all labels from an issue
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <returns></returns>
|
||||
Task RemoveAllFromIssue(string owner, string repo, int number);
|
||||
|
||||
/// <summary>
|
||||
/// Gets labels for every issue in a milestone
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the milestone</param>
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<Label>> GetForMilestone(string owner, string repo, int number);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
|
||||
namespace Octokit
|
||||
{
|
||||
@@ -122,5 +123,101 @@ namespace Octokit
|
||||
|
||||
return ApiConnection.Post<Label>(ApiUrls.Label(owner, repo, name), labelUpdate);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a label to an issue
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#add-labels-to-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <param name="labels">The names of the labels to add</param>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<Label>> AddToIssue(string owner, string repo, int number, string[] labels)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
|
||||
Ensure.ArgumentNotNull(labels, "labels");
|
||||
|
||||
return ApiConnection.Post<IReadOnlyList<Label>>(ApiUrls.IssueLabels(owner, repo, number), labels);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes a label from an issue
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <param name="label">The name of the label to remove</param>
|
||||
/// <returns></returns>
|
||||
public Task RemoveFromIssue(string owner, string repo, int number, string label)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
|
||||
Ensure.ArgumentNotNullOrEmptyString(label, "label");
|
||||
|
||||
return ApiConnection.Delete(ApiUrls.IssueLabel(owner, repo, number, label));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replaces all labels on the specified issues with the provided labels
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <param name="labels">The names of the labels to set</param>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<Label>> ReplaceAllForIssue(string owner, string repo, int number, string[] labels)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
|
||||
Ensure.ArgumentNotNull(labels, "labels");
|
||||
|
||||
return ApiConnection.Put<IReadOnlyList<Label>>(ApiUrls.IssueLabels(owner, repo, number), labels);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes all labels from an issue
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#remove-all-labels-from-an-issue">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the issue</param>
|
||||
/// <returns></returns>
|
||||
public Task RemoveAllFromIssue(string owner, string repo, int number)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
|
||||
|
||||
return ApiConnection.Delete(ApiUrls.IssueLabels(owner, repo, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets labels for every issue in a milestone
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="http://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone">API documentation</a> for more information.
|
||||
/// </remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The number of the milestone</param>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<Label>> GetForMilestone(string owner, string repo, int number)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(repo, "repo");
|
||||
|
||||
return ApiConnection.GetAll<Label>(ApiUrls.MilestoneLabels(owner, repo, number));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ namespace Octokit
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all of the labels for the specified issue.
|
||||
/// Returns the <see cref="Uri"/> that returns the named label for the specified issue.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
@@ -399,7 +399,7 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
public static Uri IssueLabel(string owner, string repo, int number, string name)
|
||||
{
|
||||
return "repos/{0}/{1}/issues/{2}/label/{3}".FormatUri(owner, repo, number, name);
|
||||
return "repos/{0}/{1}/issues/{2}/labels/{3}".FormatUri(owner, repo, number, name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -414,6 +414,18 @@ namespace Octokit
|
||||
return "repos/{0}/{1}/issues/{2}/labels".FormatUri(owner, repo, number);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all of the labels for all issues in the specified milestone.
|
||||
/// </summary>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="repo">The name of the repository</param>
|
||||
/// <param name="number">The milestone number</param>
|
||||
/// <returns></returns>
|
||||
public static Uri MilestoneLabels(string owner, string repo, int number)
|
||||
{
|
||||
return "repos/{0}/{1}/milestones/{2}/labels".FormatUri(owner, repo, number);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that lists the commit statuses for the specified reference.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user