mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-05 23:06:10 +00:00
feat: Adds cancel invitation
* Added api request to cancel an organization invitation * Added tests --------- Co-authored-by: Nick Floyd <139819+nickfloyd@users.noreply.github.com>
This commit is contained in:
@@ -363,7 +363,19 @@ namespace Octokit.Reactive
|
||||
/// <param name="options">Options to change API behaviour</param>
|
||||
/// <returns></returns>
|
||||
IObservable<OrganizationMembershipInvitation> GetAllFailedInvitations(string org, ApiOptions options);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://docs.github.com/en/rest/orgs/members#cancel-an-organization-invitation">API Documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org">The login for the organization</param>
|
||||
/// <param name="invitationId">The unique identifier of the invitation</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> CancelOrganizationInvitation(string org, int invitationId);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="OrganizationMembership" />s for the current user.
|
||||
/// </summary>
|
||||
|
||||
@@ -507,6 +507,25 @@ namespace Octokit.Reactive
|
||||
return _connection.GetAndFlattenAllPages<OrganizationMembershipInvitation>(ApiUrls.OrganizationFailedInvitations(org), null, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://docs.github.com/en/rest/orgs/members#cancel-an-organization-invitation">API Documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org">The login for the organization</param>
|
||||
/// <param name="invitationId">The unique identifier of the invitation</param>
|
||||
/// <returns></returns>
|
||||
[ManualRoute("DELETE", "/orgs/{org}/invitations/{invitation_id}")]
|
||||
public IObservable<Unit> CancelOrganizationInvitation(string org, int invitationId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
||||
Ensure.ArgumentNotNullOrDefault(invitationId, nameof(invitationId));
|
||||
|
||||
return _client.CancelOrganizationInvitation(org, invitationId).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="OrganizationMembership" />s for the current user.
|
||||
/// </summary>
|
||||
|
||||
@@ -628,5 +628,29 @@ namespace Octokit.Tests.Clients
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllPendingInvitations("org", null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCancelOrganizationInvitationMethod
|
||||
{
|
||||
[Fact]
|
||||
public void PostsToCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new OrganizationMembersClient(connection);
|
||||
|
||||
client.CancelOrganizationInvitation("org", 1);
|
||||
|
||||
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "orgs/org/invitations/1"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsureNonNullArguments()
|
||||
{
|
||||
var client = new OrganizationMembersClient(Substitute.For<IApiConnection>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CancelOrganizationInvitation(null, 1));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CancelOrganizationInvitation("", 1));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CancelOrganizationInvitation("org", 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -434,5 +434,29 @@ namespace Octokit.Tests.Reactive
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllPendingInvitations("org", null).ToTask());
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCancelOrganizationInvitationMethod
|
||||
{
|
||||
[Fact]
|
||||
public void CancelInvitationFromClientOrganizationMember()
|
||||
{
|
||||
var gitHubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableOrganizationMembersClient(gitHubClient);
|
||||
|
||||
client.CancelOrganizationInvitation("org", 1);
|
||||
|
||||
gitHubClient.Organization.Member.Received().CancelOrganizationInvitation("org", 1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresNonNullArguments()
|
||||
{
|
||||
var client = new ObservableOrganizationMembersClient(Substitute.For<IGitHubClient>());
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CancelOrganizationInvitation(null, 1).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CancelOrganizationInvitation("", 1).ToTask());
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CancelOrganizationInvitation("org", 0).ToTask());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,6 +370,18 @@ namespace Octokit
|
||||
/// <returns></returns>
|
||||
Task<IReadOnlyList<OrganizationMembershipInvitation>> GetAllFailedInvitations(string org, ApiOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://docs.github.com/en/rest/orgs/members#cancel-an-organization-invitation">API Documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org">The login for the organization</param>
|
||||
/// <param name="invitationId">The unique identifier of the invitation</param>
|
||||
/// <returns></returns>
|
||||
Task CancelOrganizationInvitation(string org, int invitationId);
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="OrganizationMembership" />s for the current user.
|
||||
/// </summary>
|
||||
|
||||
@@ -604,6 +604,25 @@ namespace Octokit
|
||||
return ApiConnection.GetAll<OrganizationMembershipInvitation>(ApiUrls.OrganizationFailedInvitations(org), null, options);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cancel an organization invitation. In order to cancel an organization invitation, the authenticated user must be an organization owner.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// See the <a href="https://docs.github.com/en/rest/orgs/members#cancel-an-organization-invitation">API Documentation</a>
|
||||
/// for more information.
|
||||
/// </remarks>
|
||||
/// <param name="org">The login for the organization</param>
|
||||
/// <param name="invitationId">The unique identifier of the invitation</param>
|
||||
/// <returns></returns>
|
||||
[ManualRoute("DELETE", "/orgs/{org}/invitations/{invitation_id}")]
|
||||
public Task CancelOrganizationInvitation(string org, int invitationId)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(org, nameof(org));
|
||||
Ensure.ArgumentNotNullOrDefault(invitationId, nameof(invitationId));
|
||||
|
||||
return ApiConnection.Delete(ApiUrls.CancelOrganizationInvitation(org, invitationId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns all <see cref="OrganizationMembership" />s for the current user.
|
||||
/// </summary>
|
||||
|
||||
@@ -943,6 +943,17 @@ namespace Octokit
|
||||
return "orgs/{0}/failed_invitations".FormatUri(org);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> to cancel an organization invitation
|
||||
/// </summary>
|
||||
/// <param name="org">The name of the organization</param>
|
||||
/// <param name="invitationId">The unique identifier of the invitation</param>
|
||||
/// <returns></returns>
|
||||
public static Uri CancelOrganizationInvitation(string org, int invitationId)
|
||||
{
|
||||
return "orgs/{0}/invitations/{1}".FormatUri(org, invitationId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the <see cref="Uri"/> that returns all of the outside collaborators of the organization
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user