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

Add getUser method and User.AvatarUrl property #4

Merged
merged 1 commit into from
Nov 15, 2017

Conversation

thomaslevesque
Copy link

@@ -148,6 +148,20 @@ public User getCurrentUser()
return user.Data;
}

public User getUser(string username)
Copy link
Member

Choose a reason for hiding this comment

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

The method must be in PascalCase (e.g. GetUser) and arguments must be in camelCase (e.g. userName)
https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/capitalization-conventions

Copy link
Author

Choose a reason for hiding this comment

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

I would usually agree, but everything else in this class follows camelCase, so I did it too... I can change it if you want, but then it will be inconsistent. I'll fix the param name, though.

Copy link
Member

Choose a reason for hiding this comment

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

I haven't actually looked at the existing code at all.
CamelCase is soooo Javaish and not C#ish

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, I know... But the current code is like this. So, which is worse? Using camelCase, or having inconsistent naming? I don't mind either way, just let me know ;)

Copy link
Member

Choose a reason for hiding this comment

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

I've looked through the codebase and for the most part it looks to adhere to naming standards. This class is an odd ball.
So if you would please align you code with the MS naming standards.
We can get the rest fixed separately.

Copy link
Author

Choose a reason for hiding this comment

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

👍

throw new ArgumentNullException(nameof(username));

if (username.Length == 0)
throw new ArgumentException("Empty username", nameof(username));
Copy link
Member

Choose a reason for hiding this comment

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

Combine both checks into one

if (string.IsNullOrWhiteSpace(userName)) 
{
    throw new ArgumentException("Empty username", nameof(userName));
}

Copy link
Author

Choose a reason for hiding this comment

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

I made separate checks because I thought it would be better to throw ArgumentNullException for a null argument... I don't mind changing it if you prefer a single check with a less appropriate exception.

Copy link
Member

Choose a reason for hiding this comment

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

Less code the better :)
IMO two checks don't really provide any additional value in this case.

var request = new RestRequest($"/users/{username}");

var user = client.Get<User>(request);
return user.Data;
Copy link
Member

Choose a reason for hiding this comment

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

Should the method handle exceptions (e.g. connection timeout, host not found etc, 404)?

Copy link
Author

Choose a reason for hiding this comment

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

I tried to follow existing code patterns. The getCurrentUser method only checks for null and assumes it's because of bad credentials (although it could in fact be anything). But this API doesn't require authentication, so I removed this check. If you like, I could throw a "Not found" exception if the user doesn't exist, but just returning null makes sense too. As for connection timeout, etc, the other methods don't do it, so I didn't think it would make sense to do it here.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't seem the existing code makes itself concerned with error handling. So I suppose you just follow the existing patterns.
That is something we'll have to tackle separately

@RussKie
Copy link
Member

RussKie commented Nov 13, 2017 via email

@thomaslevesque
Copy link
Author

I made a fixup commit. Let me know if you want me to squash.

@RussKie
Copy link
Member

RussKie commented Nov 15, 2017 via email

@thomaslevesque
Copy link
Author

Done

@RussKie
Copy link
Member

RussKie commented Nov 15, 2017 via email

@thomaslevesque
Copy link
Author

So how is it going to get used? Are there more changes coming?

Yes, in the GitExtensions repo. I have a POC ready, but it will probably need some refactoring.

@RussKie RussKie merged commit e22e1b8 into gitextensions:master Nov 15, 2017
@thomaslevesque thomaslevesque deleted the get-user-and-avatar branch February 11, 2018 13:47
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.

2 participants