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 GetAll method to OrganizationsClient #1469

Merged

Conversation

malamour-work
Copy link
Contributor

Hi,

I noticed that the list all organizations GET /organizations listed here https://developer.github.com/v3/orgs/ was missing from the OrganizationClient. I did not find any issue related to this in the backlog.

I added the implementation in the two client that i found (Base and Observable) with the documentation and added some unit tests.

Let me know if i forgot something or if something need to be changed.

@ryangribble
Copy link
Contributor

Hi @malamour-work thanks heaps for your contribution! 😀

A couple of things for you:

Breaking changes to public interfaces/methods

Being a public API we do need to be careful about not breaking existing users and the renamed methods in ApiUrls class would currently be a "breaking" change for people. Whilst they are just helper methods, given they are public we could have users that are using them and as such I believe they would fall under our obligation to not make breaking changes without going through the normal process (see below).

It makes sense to rename the existing ApiUrls.Organizations() to ApiUrls.UserOrganizations() as you've done but technically that means the old name can't be used for the new "all organizations" URL since it needs to be obsoleted. You'll need to use a different name for that one such as ApiUrls.AllOrganizations().

Maintaining naming consistency

We try to follow a naming convention where GetAll gets the given resource, GetAllForCurrent() is for the current user, GetAllForUser() is for a nominated user etc. So in this case, GetAllOrganizations() should really just be named GetAll() since they are in the organizations client already. I realize you went with this option because the other methods were already just called GetAll but infact they SHOULD have been called GetAllForUser(string login) all this time... So it would be cool if you could rename GetAll(string user) => GetAllForUser(string login) as part of this change, and implement GetAll() as your new method rather than calling it GetAllOrganizations(). Any renames would be done following the "normal process" outlined below.

Process for breaking changes:

Create the new method/implementation/classes and mark any old ones as
[Obsolete("Please use OrganizationsClient.GetAllForUser() instead. This method will be removed in a future version")]

We wait at least 2 releases before removing the obsolete items from the code base. This gives users some notice (in the form of compiler warnings) before things change on them 👍

Let me know if you need any help with this and thanks for stepping up to correct this missing functionality!

@@ -20,6 +20,7 @@ public static partial class ApiUrls
static readonly Uri _currentUserOwnedAndMemberIssues = new Uri("user/issues", UriKind.Relative);
static readonly Uri _oauthAuthorize = new Uri("login/oauth/authorize", UriKind.Relative);
static readonly Uri _oauthAccessToken = new Uri("login/oauth/access_token", UriKind.Relative);
static readonly Uri _organizationUrl = new Uri("organizations", UriKind.Relative);
Copy link
Contributor

Choose a reason for hiding this comment

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

Id like to steer away from these class level variables (that are only used in one place anyway) in favour of just returning the Urls in the helper method below

{
return "users/{0}/orgs".FormatUri(login);
}

/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the organizations for the currently logged in user.
Copy link
Contributor

Choose a reason for hiding this comment

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

Extra text here from cut+paste 😀

Returns the that returns all of the organizations for the currently logged in user

@ryangribble
Copy link
Contributor

ryangribble commented Sep 21, 2016

Another thing I just realized is that the API docs mentions this "List organizations" API method is not paginated like normal methods (pagesize, count etc), and instead just uses the since parameter. So you wont be able to take ApiOptions in your method signature, instead you'll need a custom request class with the Since parameter. You can have a look at the Repositories.GetAllPublic(PublicRepositoryRequest request) method for some ideas on how to tackle that

…ible.

Created new client method and marked the old one [Obsolete] to be removed in a futur release.
Created a new request class to support the since attribute.
Updated the Unit Tests
Updated all the csproj to have the proper references.
Applied the modification from the review
@malamour-work
Copy link
Contributor Author

Hi @ryangribble

Thanks for your time and for the review. I did the modification you have requested.

Copy link
Contributor

@ryangribble ryangribble left a comment

Choose a reason for hiding this comment

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

Hey @malamour-work thanks for making those changes, I think we are almost done!

  • Given the "old" GetAll method has been obsoleted/renamed to GetAllForUser() I think it makes sense to also obsolete/rename the ApiUrls.Organizations() to ApiUrls.UserOrganizations() while we're going through the obsoleting process. This will aid in future consistency and remove confusion over the previous naming of these methods
  • Could you please add integration tests for your new methods so we can ensure they do work in the real world? At a minimum you'd want to make the new call and assert a non null/empty list is returned. Bonus points for a 2nd test which makes 2 calls using different "since" parameters and asserting that the lists returned are different! This is similar to the integration tests we have for methods that paginate using ApiOptions where we call the method with differing page counts and assert the returned lists are different

}

[Fact]
public async Task RequestsTheCorrectUrlWithApiOptions()
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this isn't actually using ApiOptions it should be named something else, perhaps RequestsTheCorrectUrlWithRequestParameter

Renamed the existing one to make it clear they test the user organization.
@malamour-work
Copy link
Contributor Author

Hi @ryangribble

I have obsoleted the old ApiUrls.Organizations() and created the integration tests like you requested.

If anything else let me know.

Thanks

@ryangribble
Copy link
Contributor

Thanks @malamour-work sorry I hadnt had a chance over the weekend to look at this. I will try and do it tonight.

Have you actually run the integration tests? I notice they are flagged as GitHubEnterprise (because they create organizations to then run the tests against, and create organizations is not avaialble on github.com only github enterprise). For something like a GET call, we could potentially run the test against github.com but I guess that becomes hard since we dont know what organization ID to use as the since parameter (and as time marches on, any ID used in the test will start to become further and further back in time, leading to the test retrieving larger amounts of orgs until it eventually times out!). So probably leaving the tests as GitHubEnterprise tests is fine, but we do just need to make sure they actually run succesfully of course 😀

I wll pull this down and run the tests etc and get back to you

@ryangribble
Copy link
Contributor

Sorry for the delay on this one 😭

Ive run the integration tests and made a couple of tweaks and pushed them back up.

This LGTM now - many thanks for your PR and particularly working through all the review comments 😀

LGTM

@ryangribble ryangribble merged commit 195de68 into octokit:master Nov 21, 2016
@ryangribble ryangribble changed the title Added a get all organizations method Add a GetAll method to OrganizationsClient Jan 15, 2017
@ryangribble ryangribble changed the title Add a GetAll method to OrganizationsClient Add a GetAll method to OrganizationsClient Jan 15, 2017
@ryangribble ryangribble changed the title Add a GetAll method to OrganizationsClient Add GetAll method to OrganizationsClient Jan 15, 2017
@nickfloyd nickfloyd added Type: Feature New feature or request and removed category: feature labels Oct 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants