From ddb66ed7120a9f9e45c3bf13b006173b6ff4cf86 Mon Sep 17 00:00:00 2001 From: Lian Duan Date: Fri, 10 Mar 2023 19:42:42 +0100 Subject: [PATCH] [FEAT] Implement GetAllOrganizationMembershipsForCurrent (#2654) --- .../IObservableOrganizationMembersClient.cs | 23 +++++++++++++ .../ObservableOrganizationMembersClient.cs | 29 +++++++++++++++++ .../Clients/OrganizationMembersClientTests.cs | 32 +++++++++++++++++++ Octokit/Clients/IOrganizationMembersClient.cs | 24 ++++++++++++++ Octokit/Clients/OrganizationMembersClient.cs | 24 ++++++++++++++ Octokit/Helpers/ApiUrls.cs | 9 ++++++ 6 files changed, 141 insertions(+) diff --git a/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs b/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs index 1097771f85..4c80d17f88 100644 --- a/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs +++ b/Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs @@ -363,5 +363,28 @@ public interface IObservableOrganizationMembersClient /// Options to change API behaviour /// IObservable GetAllFailedInvitations(string org, ApiOptions options); + + /// + /// Returns all s for the current user. + /// + /// + /// See the API Documentation + /// for more information. + /// + /// Thrown when a general API error occurs. + /// + IObservable GetAllOrganizationMembershipsForCurrent(); + + /// + /// Returns all s for the current user. + /// + /// + /// See the API Documentation + /// for more information. + /// + /// Thrown when a general API error occurs. + /// Options to change API behaviour + /// + IObservable GetAllOrganizationMembershipsForCurrent(ApiOptions options); } } diff --git a/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs b/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs index 1a1b547399..f7616aaceb 100644 --- a/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs +++ b/Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs @@ -506,5 +506,34 @@ public IObservable GetAllFailedInvitations(str return _connection.GetAndFlattenAllPages(ApiUrls.OrganizationFailedInvitations(org), null, options); } + + /// + /// Returns all s for the current user. + /// + /// + /// See the API Documentation + /// for more information. + /// + /// Thrown when a general API error occurs. + /// + public IObservable GetAllOrganizationMembershipsForCurrent() + { + return _connection.GetAndFlattenAllPages(ApiUrls.UserOrganizationMemberships()); + } + + /// + /// Returns all s for the current user. + /// + /// + /// See the API Documentation + /// for more information. + /// + /// Thrown when a general API error occurs. + /// Options to change API behaviour + /// + public IObservable GetAllOrganizationMembershipsForCurrent(ApiOptions options) + { + return _connection.GetAndFlattenAllPages(ApiUrls.UserOrganizationMemberships(), options); + } } } diff --git a/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs b/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs index 5e8dc01c04..16f0f8cf5d 100644 --- a/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs +++ b/Octokit.Tests.Integration/Clients/OrganizationMembersClientTests.cs @@ -293,5 +293,37 @@ public async Task ReturnsNoFailedInvitations() Assert.Empty(pendingInvitations); } } + + public class TheGetAllOrganizationMembershipsForCurrentMethod + { + private IGitHubClient _gitHub; + + public TheGetAllOrganizationMembershipsForCurrentMethod() + { + _gitHub = Helper.GetAuthenticatedClient(); + } + + [OrganizationTest] + public async Task ReturnsMemberships() + { + var memberships = await _gitHub.Organization.Member.GetAllOrganizationMembershipsForCurrent(); + Assert.NotEmpty(memberships); + } + + [OrganizationTest] + public async Task ReturnsCorrectCountOfMembersWithoutStart() + { + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1 + }; + + var memberships = await _gitHub.Organization.Member.GetAllOrganizationMembershipsForCurrent(options); + + Assert.Equal(1, memberships.Count); + } + + } } } diff --git a/Octokit/Clients/IOrganizationMembersClient.cs b/Octokit/Clients/IOrganizationMembersClient.cs index 328db251a9..222e10e558 100644 --- a/Octokit/Clients/IOrganizationMembersClient.cs +++ b/Octokit/Clients/IOrganizationMembersClient.cs @@ -369,5 +369,29 @@ public interface IOrganizationMembersClient /// Options to change API behaviour /// Task> GetAllFailedInvitations(string org, ApiOptions options); + + /// + /// Returns all s for the current user. + /// + /// + /// See the API Documentation + /// for more information. + /// + /// Thrown when a general API error occurs. + /// A list of the current user's s. + Task> GetAllOrganizationMembershipsForCurrent(); + + /// + /// Returns all s for the current user. + /// + /// + /// See the API Documentation + /// for more information. + /// + /// Thrown when a general API error occurs. + /// Options to change API behaviour + /// A list of the current user's s. + Task> GetAllOrganizationMembershipsForCurrent(ApiOptions options); + } } diff --git a/Octokit/Clients/OrganizationMembersClient.cs b/Octokit/Clients/OrganizationMembersClient.cs index d9f9d4fa9f..2e2de872ac 100644 --- a/Octokit/Clients/OrganizationMembersClient.cs +++ b/Octokit/Clients/OrganizationMembersClient.cs @@ -603,5 +603,29 @@ public Task> GetAllFailedInvitat return ApiConnection.GetAll(ApiUrls.OrganizationFailedInvitations(org), null, options); } + + /// + /// Returns all s for the current user. + /// + /// Thrown when a general API error occurs. + /// A list of the current user's s. + [ManualRoute("GET", "/user/memberships/orgs")] + public Task> GetAllOrganizationMembershipsForCurrent() + { + return ApiConnection.GetAll(ApiUrls.UserOrganizationMemberships()); + } + + /// + /// Returns all s for the current user. + /// + /// Thrown when a general API error occurs. + /// Options to change API behaviour + /// A list of the current user's s. + [ManualRoute("GET", "/user/memberships/orgs")] + public Task> GetAllOrganizationMembershipsForCurrent(ApiOptions options) + { + return ApiConnection.GetAll(ApiUrls.UserOrganizationMemberships(), options); + } + } } diff --git a/Octokit/Helpers/ApiUrls.cs b/Octokit/Helpers/ApiUrls.cs index 82621ada5a..9b1a072791 100644 --- a/Octokit/Helpers/ApiUrls.cs +++ b/Octokit/Helpers/ApiUrls.cs @@ -143,6 +143,15 @@ public static Uri UserOrganizations() { return "user/orgs".FormatUri(); } + + /// + /// Returns the that returns all of the organization memberships for the currently logged in user. + /// + /// + public static Uri UserOrganizationMemberships() + { + return "user/memberships/orgs".FormatUri(); + } /// /// Returns the that returns all of the organizations for the specified login.