[FEAT] Implement GetAllOrganizationMembershipsForCurrent (#2654)

This commit is contained in:
Lian Duan
2023-03-10 19:42:42 +01:00
committed by GitHub
parent 7f11726852
commit ddb66ed712
6 changed files with 141 additions and 0 deletions
@@ -363,5 +363,28 @@ namespace Octokit.Reactive
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
IObservable<OrganizationMembershipInvitation> GetAllFailedInvitations(string org, ApiOptions options);
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
IObservable<OrganizationMembership> GetAllOrganizationMembershipsForCurrent();
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
IObservable<OrganizationMembership> GetAllOrganizationMembershipsForCurrent(ApiOptions options);
}
}
@@ -506,5 +506,34 @@ namespace Octokit.Reactive
return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.OrganizationFailedInvitations(org), null, options);
}
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns></returns>
public IObservable<OrganizationMembership> GetAllOrganizationMembershipsForCurrent()
{
return _connection.GetAndFlattenAllPages<OrganizationMembership>(ApiUrls.UserOrganizationMemberships());
}
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
public IObservable<OrganizationMembership> GetAllOrganizationMembershipsForCurrent(ApiOptions options)
{
return _connection.GetAndFlattenAllPages<OrganizationMembership>(ApiUrls.UserOrganizationMemberships(), options);
}
}
}
@@ -293,5 +293,37 @@ namespace Octokit.Tests.Integration.Clients
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);
}
}
}
}
@@ -369,5 +369,29 @@ namespace Octokit
/// <param name="options">Options to change API behaviour</param>
/// <returns></returns>
Task<IReadOnlyList<OrganizationMembershipInvitation>> GetAllFailedInvitations(string org, ApiOptions options);
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the current user's <see cref="OrganizationMembership"/>s.</returns>
Task<IReadOnlyList<OrganizationMembership>> GetAllOrganizationMembershipsForCurrent();
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <remarks>
/// See the <a href="https://docs.github.com/en/rest/orgs/members#list-organization-memberships-for-the-authenticated-user">API Documentation</a>
/// for more information.
/// </remarks>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <param name="options">Options to change API behaviour</param>
/// <returns>A list of the current user's <see cref="OrganizationMembership"/>s.</returns>
Task<IReadOnlyList<OrganizationMembership>> GetAllOrganizationMembershipsForCurrent(ApiOptions options);
}
}
@@ -603,5 +603,29 @@ namespace Octokit
return ApiConnection.GetAll<OrganizationMembershipInvitation>(ApiUrls.OrganizationFailedInvitations(org), null, options);
}
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <returns>A list of the current user's <see cref="OrganizationMembership"/>s.</returns>
[ManualRoute("GET", "/user/memberships/orgs")]
public Task<IReadOnlyList<OrganizationMembership>> GetAllOrganizationMembershipsForCurrent()
{
return ApiConnection.GetAll<OrganizationMembership>(ApiUrls.UserOrganizationMemberships());
}
/// <summary>
/// Returns all <see cref="OrganizationMembership" />s for the current user.
/// </summary>
/// <exception cref="ApiException">Thrown when a general API error occurs.</exception>
/// <param name="options">Options to change API behaviour</param>
/// <returns>A list of the current user's <see cref="OrganizationMembership"/>s.</returns>
[ManualRoute("GET", "/user/memberships/orgs")]
public Task<IReadOnlyList<OrganizationMembership>> GetAllOrganizationMembershipsForCurrent(ApiOptions options)
{
return ApiConnection.GetAll<OrganizationMembership>(ApiUrls.UserOrganizationMemberships(), options);
}
}
}
+9
View File
@@ -143,6 +143,15 @@ namespace Octokit
{
return "user/orgs".FormatUri();
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the organization memberships for the currently logged in user.
/// </summary>
/// <returns></returns>
public static Uri UserOrganizationMemberships()
{
return "user/memberships/orgs".FormatUri();
}
/// <summary>
/// Returns the <see cref="Uri"/> that returns all of the organizations for the specified login.