Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/octokit#2870
Browse files Browse the repository at this point in the history
  • Loading branch information
nickfloyd committed Feb 21, 2024
2 parents 768a1dd + 40041f2 commit e8bee6d
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ FROM mcr.microsoft.com/vscode/devcontainers/dotnet
COPY --from=mcr.microsoft.com/dotnet/sdk:6.0 /usr/share/dotnet/shared /usr/share/dotnet/shared

# # Add mkdocs for doc generation
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends python3-pip
RUN pip3 install mkdocs
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && apt-get -y install --no-install-recommends python3-pip
# RUN pip3 install mkdocs

RUN apt-get install -y mono-complete
7 changes: 3 additions & 4 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ Resolves #ISSUE_NUMBER
### Before the change?
<!-- Please describe the current behavior that you are modifying. -->

*
*

### After the change?
<!-- Please describe the behavior or changes that are being added by this PR. -->

*
*

### Pull request checklist
- [ ] Tests for the changes have been added (for bug fixes / features)
Expand All @@ -21,10 +21,9 @@ Resolves #ISSUE_NUMBER
### Does this introduce a breaking change?
<!-- If this introduces a breaking change make sure to note it here any what the impact might be -->

Please see our docs on [breaking changes](https://github.com/octokit/.github/blob/master/community/breaking_changes.md) to help!
Please see our docs on [breaking changes](https://github.com/octokit/.github/blob/main/community/breaking_changes.md) to help!

- [ ] Yes
- [ ] No

----

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,5 @@ Some things that will increase the chance that your pull request is accepted:

# Additional Resources

* [Octokit Codebase Overview](https://github.com/octokit/octokit.net/blob/master/OVERVIEW.md)
* [Octokit Codebase Overview](https://github.com/octokit/octokit.net/blob/main/OVERVIEW.md)
* [General GitHub documentation](http://help.github.com/)
14 changes: 13 additions & 1 deletion Octokit.Reactive/Clients/IObservableOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,19 @@ public interface IObservableOrganizationMembersClient
/// <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>
Expand Down
19 changes: 19 additions & 0 deletions Octokit.Reactive/Clients/ObservableOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,25 @@ public IObservable<OrganizationMembershipInvitation> GetAllFailedInvitations(str
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>
Expand Down
6 changes: 3 additions & 3 deletions Octokit.Tests.Conventions/Octokit.Tests.Conventions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ internal async static Task ProtectDefaultBranch(this IGitHubClient client, Repos
true,
true,
true,
true,
false,
true);

Expand All @@ -55,6 +56,8 @@ internal async static Task<RepositoryContext> CreateRepositoryWithProtectedBranc
true,
true,
true,
true,
true,
false,
true);

Expand Down
6 changes: 3 additions & 3 deletions Octokit.Tests.Integration/Octokit.Tests.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

<ItemGroup>
<PackageReference Include="GitHubJwt" Version="0.0.6" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.IO.Compression" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public async Task UpdatesBranchProtectionForOrgRepo()
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2),
new BranchProtectionPushRestrictionsUpdate(),
true,
false,
true,
true,
Expand All @@ -211,6 +212,7 @@ public async Task UpdatesBranchProtectionForOrgRepo()
Assert.Empty(protection.Restrictions.Teams);
Assert.Empty(protection.Restrictions.Users);

Assert.True(protection.RequiredSignatures.Enabled);
Assert.False(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredLinearHistory.Enabled);
Assert.True(protection.AllowForcePushes.Enabled);
Expand All @@ -230,6 +232,7 @@ public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId()
new BranchProtectionRequiredStatusChecksUpdate(false, new[] { "new" }),
new BranchProtectionRequiredReviewsUpdate(new BranchProtectionRequiredReviewsDismissalRestrictionsUpdate(false), false, false, 2),
new BranchProtectionPushRestrictionsUpdate(),
true,
false,
true,
true,
Expand All @@ -250,6 +253,7 @@ public async Task UpdatesBranchProtectionForOrgRepoWithRepositoryId()
Assert.Empty(protection.Restrictions.Teams);
Assert.Empty(protection.Restrictions.Users);

Assert.True(protection.RequiredSignatures.Enabled);
Assert.False(protection.EnforceAdmins.Enabled);
Assert.True(protection.RequiredLinearHistory.Enabled);
Assert.True(protection.AllowForcePushes.Enabled);
Expand Down
24 changes: 24 additions & 0 deletions Octokit.Tests/Clients/OrganizationMembersClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,5 +628,29 @@ public async Task EnsureNonNullArguments()
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));
}
}
}
}
6 changes: 3 additions & 3 deletions Octokit.Tests/Octokit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6" />
<PackageReference Include="xunit" Version="2.7.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.7" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
Expand Down
24 changes: 24 additions & 0 deletions Octokit.Tests/Reactive/ObservableOrganizationMembersClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,5 +434,29 @@ public async Task EnsuresNonNullArguments()
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());
}
}
}
}
12 changes: 12 additions & 0 deletions Octokit/Clients/IOrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,18 @@ public interface IOrganizationMembersClient
/// <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>
Expand Down
19 changes: 19 additions & 0 deletions Octokit/Clients/OrganizationMembersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,25 @@ public Task<IReadOnlyList<OrganizationMembershipInvitation>> GetAllFailedInvitat
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>
Expand Down
11 changes: 11 additions & 0 deletions Octokit/Helpers/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,17 @@ public static Uri OrganizationFailedInvitations(string org)
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>
Expand Down
8 changes: 8 additions & 0 deletions Octokit/Models/Request/BranchProtectionUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate
/// <param name="requiredStatusChecks">Specifies the requested status check settings. Pass null to disable status checks</param>
/// <param name="requiredPullRequestReviews">Specifies if reviews are required to merge the pull request. Pass null to disable required reviews</param>
/// <param name="restrictions">Specifies the requested push access restrictions (applies only to Organization owned repositories). Pass null to disable push access restrictions</param>
/// <param name="requiredSignatures">Specifies whether commits to a branch are required to be signed by gpg keys</param>
/// <param name="enforceAdmins">Specifies whether the protections applied to this branch also apply to repository admins</param>
/// <param name="requiredLinearHistory">Enforces a linear commit Git history</param>
/// <param name="allowForcePushes">Permits force pushes to the protected branch</param>
Expand All @@ -122,6 +123,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate
public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate requiredStatusChecks,
BranchProtectionRequiredReviewsUpdate requiredPullRequestReviews,
BranchProtectionPushRestrictionsUpdate restrictions,
bool requiredSignatures,
bool enforceAdmins,
bool requiredLinearHistory,
bool? allowForcePushes,
Expand All @@ -133,6 +135,7 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate
RequiredStatusChecks = requiredStatusChecks;
RequiredPullRequestReviews = requiredPullRequestReviews;
Restrictions = restrictions;
RequiredSignatures = requiredSignatures;
EnforceAdmins = enforceAdmins;
LockBranch = lockBranch;
RequiredLinearHistory = requiredLinearHistory;
Expand All @@ -159,6 +162,11 @@ public BranchProtectionSettingsUpdate(BranchProtectionRequiredStatusChecksUpdate
/// </summary>
[SerializeNull]
public BranchProtectionPushRestrictionsUpdate Restrictions { get; protected set; }

/// <summary>
/// Specifies whether the signed commits are required for this branch
/// </summary>
public bool RequiredSignatures { get; set; }

/// <summary>
/// Specifies whether the protections applied to this branch also apply to repository admins
Expand Down
2 changes: 2 additions & 0 deletions Octokit/Models/Response/WorkflowJobStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public enum WorkflowJobStatus
Completed,
[Parameter(Value = "waiting")]
Waiting,
[Parameter(Value = "pending")]
Pending,
}
}
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Thanks for helping make GitHub Open Source Software safe for everyone.

GitHub takes the security of our software products and services seriously, including all of the open source code repositories managed through our GitHub organizations, such as [Octokit](https://github.com/octokit).

Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we want to make sure that your finding gets passed along to the maintainers of this project for remediation.
Even though [open source repositories are outside of the scope of our bug bounty program](https://bounty.github.com/index.html#scope) and therefore not eligible for bounty rewards, we want to make sure that your finding gets passed along to the maintainers of this project for remediation.


## Reporting a Vulnerability

Since this source is part of [Octokit](https://github.com/octokit) (a GitHub organization) we ask that you follow the guidelines [here](https://github.com/github/.github/blob/master/SECURITY.md#reporting-security-issues) to report anything that you might've found.
Since this source is part of [Octokit](https://github.com/octokit) (a GitHub organization) we ask that you follow the guidelines [here](https://github.com/github/.github/blob/main/SECURITY.md#reporting-security-issues) to report anything that you might've found.

0 comments on commit e8bee6d

Please sign in to comment.