Skip to content

Commit

Permalink
[FEAT] Implement GetAllOrganizationMembershipsForCurrent (#2654)
Browse files Browse the repository at this point in the history
  • Loading branch information
chemhack authored Mar 10, 2023
1 parent 7f11726 commit ddb66ed
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,5 +363,28 @@ public interface IObservableOrganizationMembersClient
/// <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);
}
}
29 changes: 29 additions & 0 deletions Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -506,5 +506,34 @@ public IObservable<OrganizationMembershipInvitation> GetAllFailedInvitations(str

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
}
}
24 changes: 24 additions & 0 deletions Octokit/Clients/IOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,29 @@ public interface IOrganizationMembersClient
/// <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);

}
}
24 changes: 24 additions & 0 deletions Octokit/Clients/OrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -603,5 +603,29 @@ public Task<IReadOnlyList<OrganizationMembershipInvitation>> GetAllFailedInvitat

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 changes: 9 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ public static Uri UserOrganizations()
{
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.
Expand Down

0 comments on commit ddb66ed

Please sign in to comment.