Skip to content
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 10 commits into from
Dec 8, 2013
Merged

Implement labels CRUD #256

merged 10 commits into from
Dec 8, 2013

Conversation

andrerod
Copy link

@andrerod andrerod commented Dec 5, 2013

Implements:
#254

@andrerod
Copy link
Author

andrerod commented Dec 5, 2013

@paulcbetts if this looks good i'll add some tests as well.

/// http://developer.github.com/v3/repos/:owner/:repo/labels/:name
/// </remarks>
/// <returns></returns>
Task<IReadOnlyList<Label>> GetForRepository(string owner, string repo);
Copy link
Member

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...

/// <summary>
/// Gets a specific <see cref="Authorization"/> for the authenticated user.
/// </summary>
/// <remarks>
/// This method requires authentication.
/// See the <a href="http://developer.github.com/v3/oauth/#get-a-single-authorization">API documentation</a> for more information.
/// </remarks>
/// <param name="id">The ID of the <see cref="Authorization"/> to get</param>
/// <exception cref="AuthorizationException">
/// Thrown when the current user does not have permission to make this request.
/// </exception>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>The specified <see cref="Authorization"/>.</returns>

@shiftkey
Copy link
Member

shiftkey commented Dec 5, 2013

@andrerod looking good so far, just a few little things about documentation

I'd also ❤️ some tests if you've got time!

@andrerod
Copy link
Author

andrerod commented Dec 6, 2013

@shiftkey updated.

using Octokit.Tests.Integration;
using Xunit;

public class IssuesLabelsClientTests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to implement IDisposable so we clean up the repository correctly after the test (this is just an xUnit convention)

@andrerod
Copy link
Author

andrerod commented Dec 6, 2013

@shiftkey Good point. Updated again. (also added IDisposable for events which was also missing)

/// <returns></returns>
public static Uri IssueLabels(string owner, string repo, int number)
{
return "repos/{0}/{1}/issues/{2}/label".FormatUri(owner, repo, number);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be "repos/{0}/{1}/issues/{2}/labels"

http://developer.github.com/v3/issues/labels/#list-labels-on-an-issue


await client.GetForIssue("fake", "repo", 42);

connection.Received().GetAll<EventInfo>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/labels"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you're testing NSubstitute mocks, you'll need to ensure the right generic parameters are specified.

So these tests should look for <Label> - that's one of the reasons why these tests fail

@shiftkey
Copy link
Member

shiftkey commented Dec 6, 2013

@andrerod can you also run .\build FixProjects to sync the new files with the Mono* projects?

public async Task CanListLabelsForAnIssue()
{
var newIssue = new NewIssue("A test issue") { Body = "A new unassigned issue" };
var newLabel = new NewLabel("test label", "#FFFFFF");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The color value must not contain the leading #

Can we do some validation in here to ensure users supply this in the correct format?

@andrerod
Copy link
Author

andrerod commented Dec 6, 2013

Done

get { return _color; }
set
{
if (!string.IsNullOrEmpty(value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this logic needs to be flipped, because valid inputs end up throwing the exception

@andrerod
Copy link
Author

andrerod commented Dec 8, 2013

@shiftkey : updated and added the same validation logic on the update class.

{
if (!string.IsNullOrEmpty(value)
&& value.Length == 6
&& Regex.IsMatch(value, @"\A\b[0-9a-fA-F]+\b\Z"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not that I'm a Regex guru, but could you just condense this down to:

\A\b[0-9a-fA-F]{6}\b\Z

and make the if statement more terse?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @haacked for his regex opinions:

http://developer.github.com/v3/issues/labels/#create-a-label

{
  "name": "API",
  "color": "FFFFFF"
}

color: Required. A 6 character hex code, without the leading #, identifying the color.

set
{
if (string.IsNullOrEmpty(value)
|| value.Length != 6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the length check be added to the Regex check?
And I think the null check will be caught by the regex too so that's probably redundant here...

get { return _color; }
set
{
if (!Regex.IsMatch(value, @"\A\b[0-9a-fA-F]{6}\b\Z"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right, this throws a different exception to the one we want.

We've been using ctor checks (like this one) to catch most of the bad input like that. Would that be worth plugging into these classes?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh. Argument null is probably the right exception anyways. So I think you were actually right although both would work.

As for the ctor check, i'm using the property setter to set the value in the constructor, so this check will happen there as well so IMO I think we're good in that regard. Unless you have a different opinion :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the ctor check, i'm using the property setter to set the value in the constructor,

It'd be good to enforce such checks for the ctor anyway ("let's send a null label name to the API!" for example)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the null checks in the ctor. Is that what you had in mind ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly (well, ArgumentNotNullOrEmptyString specifically but I wasn't clear on that)

@shiftkey
Copy link
Member

shiftkey commented Dec 8, 2013

Right, I'm all happy with this now. Thank for the contribution!

tumblr_inline_mncxgo2qq51qz4rgp

shiftkey added a commit that referenced this pull request Dec 8, 2013
@shiftkey shiftkey merged commit e73be93 into octokit:master Dec 8, 2013
@andrerod
Copy link
Author

andrerod commented Dec 8, 2013

You're welcome! Thanks for the effort and for taking it.

@andrerod
Copy link
Author

andrerod commented Dec 8, 2013

p.s.- don't forget to close the associated issue.

@shiftkey shiftkey mentioned this pull request Dec 8, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants