-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement labels CRUD #256
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8f44a22
Implement labels CRUD
2ab931b
Apply review comments
891a353
Add disposable
dc9a059
Fix URI
18a3d39
Apply more review comments
0a484c0
Fixing projects
7c64c17
Fix validation logic
4697c96
Update regex expression
a3ff363
Remove null check
63da0a6
Add null checks in constructor
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
Octokit.Tests.Integration/Clients/IssuesLabelsClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.Linq; | ||
using System.Net.Http.Headers; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Octokit; | ||
using Octokit.Tests.Integration; | ||
using Xunit; | ||
|
||
public class IssuesLabelsClientTests : IDisposable | ||
{ | ||
readonly IGitHubClient _gitHubClient; | ||
readonly IIssuesLabelsClient _issuesLabelsClient; | ||
readonly IIssuesClient _issuesClient; | ||
readonly Repository _repository; | ||
readonly string _repositoryOwner; | ||
readonly string _repositoryName; | ||
|
||
public IssuesLabelsClientTests() | ||
{ | ||
_gitHubClient = new GitHubClient(new ProductHeaderValue("OctokitTests")) | ||
{ | ||
Credentials = Helper.Credentials | ||
}; | ||
_issuesLabelsClient= _gitHubClient.Issue.Labels; | ||
_issuesClient = _gitHubClient.Issue; | ||
var repoName = Helper.MakeNameWithTimestamp("public-repo"); | ||
|
||
_repository = _gitHubClient.Repository.Create(new NewRepository { Name = repoName }).Result; | ||
_repositoryOwner = _repository.Owner.Login; | ||
_repositoryName = _repository.Name; | ||
} | ||
|
||
[IntegrationTest] | ||
public async Task CanListLabelsForAnIssue() | ||
{ | ||
var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" }; | ||
var newLabel = new NewLabel("test label", "FFFFFF"); | ||
|
||
var label = await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel); | ||
var issue = await _issuesClient.Create(_repositoryOwner, _repositoryName, newIssue); | ||
|
||
var issueLabelsInfo = await _issuesLabelsClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number); | ||
Assert.Empty(issueLabelsInfo); | ||
|
||
var issueUpdate = new IssueUpdate(); | ||
issueUpdate.Labels.Add(label.Name); | ||
var updated = await _issuesClient.Update(_repositoryOwner, _repository.Name, issue.Number, issueUpdate); | ||
Assert.NotNull(updated); | ||
issueLabelsInfo = await _issuesLabelsClient.GetForIssue(_repositoryOwner, _repositoryName, issue.Number); | ||
|
||
Assert.Equal(1, issueLabelsInfo.Count); | ||
Assert.Equal(newLabel.Color, issueLabelsInfo[0].Color); | ||
} | ||
|
||
[IntegrationTest] | ||
public async Task CanListIssueLabelsForARepository() | ||
{ | ||
var newLabel1 = new NewLabel("test label 1", "FFFFFF"); | ||
var newLabel2 = new NewLabel("test label 2", "FFFFFF"); | ||
|
||
var originalIssueLabels = await _issuesLabelsClient.GetForRepository(_repositoryOwner, _repositoryName); | ||
|
||
await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel1); | ||
await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel2); | ||
|
||
var issueLabels = await _issuesLabelsClient.GetForRepository(_repositoryOwner, _repositoryName); | ||
|
||
Assert.Equal(originalIssueLabels.Count + 2, issueLabels.Count); | ||
} | ||
|
||
[IntegrationTest] | ||
public async Task CanRetrieveIssueLabelByName() | ||
{ | ||
var newLabel = new NewLabel("test label 1b", "FFFFFF"); | ||
var label = await _issuesLabelsClient.Create(_repositoryOwner, _repository.Name, newLabel); | ||
Assert.NotNull(label); | ||
|
||
var issueLabelLookupByName = await _issuesLabelsClient.Get(_repositoryOwner, _repositoryName, label.Name); | ||
|
||
Assert.Equal(label.Name, issueLabelLookupByName.Name); | ||
Assert.Equal(label.Color, issueLabelLookupByName.Color); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
Helper.DeleteRepo(_repository); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using Octokit.Tests.Helpers; | ||
using Xunit; | ||
|
||
namespace Octokit.Tests.Clients | ||
{ | ||
public class IssuesLabelsClientTests | ||
{ | ||
public class TheGetForIssueMethod | ||
{ | ||
[Fact] | ||
public async Task RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new IssuesLabelsClient(connection); | ||
|
||
await client.GetForIssue("fake", "repo", 42); | ||
|
||
connection.Received().GetAll<Label>(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.Get(null, "name", "label")); | ||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "label")); | ||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", "name", null)); | ||
} | ||
} | ||
|
||
public class TheGetForRepositoryMethod | ||
{ | ||
[Fact] | ||
public async Task RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new IssuesLabelsClient(connection); | ||
|
||
await client.GetForRepository("fake", "repo"); | ||
|
||
connection.Received().GetAll<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels")); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArguments() | ||
{ | ||
var client = new IssuesLabelsClient(Substitute.For<IApiConnection>()); | ||
|
||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", "label")); | ||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "label")); | ||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", "name", null)); | ||
} | ||
} | ||
|
||
public class TheGetMethod | ||
{ | ||
[Fact] | ||
public void RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new IssuesLabelsClient(connection); | ||
|
||
client.Get("fake", "repo", "label"); | ||
|
||
connection.Received().Get<Label>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/labels/label"), | ||
null); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArguments() | ||
{ | ||
var client = new IssuesLabelsClient(Substitute.For<IApiConnection>()); | ||
|
||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", "label")); | ||
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "label")); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit | ||
{ | ||
public interface IIssuesLabelsClient | ||
{ | ||
/// <summary> | ||
/// Gets all labels for the issue. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/issues/labels/#list-labels-on-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>The list of labels</returns> | ||
Task<IReadOnlyList<Label>> GetForIssue(string owner, string repo, int number); | ||
|
||
/// <summary> | ||
/// Gets all labels for the repository. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/issues/labels/#list-all-labels-for-this-repository">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> | ||
/// <returns>The list of labels</returns> | ||
Task<IReadOnlyList<Label>> GetForRepository(string owner, string repo); | ||
|
||
/// <summary> | ||
/// Gets a single Label by name. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/issues/labels/#get-a-single-label">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="name">The name of the label</param> | ||
/// <returns>The label</returns> | ||
[SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get", | ||
Justification = "Method makes a network request")] | ||
Task<Label> Get(string owner, string repo, string name); | ||
|
||
/// <summary> | ||
/// Deletes a label. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/issues/labels/#delete-a-label">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="name">The name of the label</param> | ||
/// <returns></returns> | ||
Task Delete(string owner, string repo, string name); | ||
|
||
/// <summary> | ||
/// Creates a label. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/issues/labels/#create-a-label">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="newLabel">The data for the label to be created</param> | ||
/// <returns>The created label</returns> | ||
Task<Label> Create(string owner, string repo, NewLabel newLabel); | ||
|
||
/// <summary> | ||
/// Updates a label. | ||
/// </summary> | ||
/// <remarks> | ||
/// See the <a href="http://developer.github.com/v3/issues/labels/#update-a-label">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="name">The name of the label</param> | ||
/// <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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be great if you could document these signatures like how we document the other clients.
There's probably things in here which aren't relevant to your use case...