mirror of
https://github.com/zoriya/octokit.net.git
synced 2025-12-06 07:16:09 +00:00
Add method to check if repo vulnerability alerts are enabled (#2453)
This commit is contained in:
@@ -72,6 +72,17 @@ namespace Octokit.Reactive
|
|||||||
/// <returns>A <see cref="Repository"/></returns>
|
/// <returns>A <see cref="Repository"/></returns>
|
||||||
IObservable<Repository> Transfer(long repositoryId, RepositoryTransfer repositoryTransfer);
|
IObservable<Repository> Transfer(long repositoryId, RepositoryTransfer repositoryTransfer);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if vulnerability alerts are enabled for the specified repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// See the <a href="https://docs.github.com/en/rest/reference/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository">API documentation</a> for more information.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="owner">The current owner of the repository</param>
|
||||||
|
/// <param name="name">The name of the repository</param>
|
||||||
|
/// <returns>A <c>bool</c> indicating if alerts are turned on or not.</returns>
|
||||||
|
IObservable<bool> AreVulnerabilityAlertsEnabled(string owner, string name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
|
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -151,6 +151,23 @@ namespace Octokit.Reactive
|
|||||||
return _client.Transfer(repositoryId, repositoryTransfer).ToObservable();
|
return _client.Transfer(repositoryId, repositoryTransfer).ToObservable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if vulnerability alerts are enabled for the specified repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// See the <a href="https://docs.github.com/en/rest/reference/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository">API documentation</a> for more information.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="owner">The current owner of the repository</param>
|
||||||
|
/// <param name="name">The name of the repository</param>
|
||||||
|
/// <returns>A <c>bool</c> indicating if alerts are turned on or not.</returns>
|
||||||
|
public IObservable<bool> AreVulnerabilityAlertsEnabled(string owner, string name)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
|
||||||
|
|
||||||
|
return _client.AreVulnerabilityAlertsEnabled(owner, name).ToObservable();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
|
/// Retrieves the <see cref="Repository"/> for the specified owner and name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2055,4 +2055,15 @@ public class RepositoriesClientTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TheAreVulnerabilityAlertsEnabledMethod
|
||||||
|
{
|
||||||
|
[IntegrationTest]
|
||||||
|
public async Task AreVulnerabilityAlertsEnabledReturnsTrue()
|
||||||
|
{
|
||||||
|
var github = Helper.GetAuthenticatedClient();
|
||||||
|
var enabled = await github.Repository.AreVulnerabilityAlertsEnabled("owner", "name");
|
||||||
|
Assert.True(enabled);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,11 @@ using System.Collections.Generic;
|
|||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
|
using Octokit.Internal;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
using static Octokit.Internal.TestSetup;
|
||||||
|
|
||||||
namespace Octokit.Tests.Clients
|
namespace Octokit.Tests.Clients
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -395,6 +398,55 @@ namespace Octokit.Tests.Clients
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TheAreVulnerabilityAlertsEnabledMethod
|
||||||
|
{
|
||||||
|
[Theory]
|
||||||
|
[InlineData(HttpStatusCode.NoContent, true)]
|
||||||
|
[InlineData(HttpStatusCode.NotFound, false)]
|
||||||
|
public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected)
|
||||||
|
{
|
||||||
|
var response = CreateResponse(status);
|
||||||
|
var responseTask = Task.FromResult<IApiResponse<object>>(new ApiResponse<object>(response));
|
||||||
|
var connection = Substitute.For<IConnection>();
|
||||||
|
connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/vulnerability-alerts"),
|
||||||
|
null, null).Returns(responseTask);
|
||||||
|
var apiConnection = Substitute.For<IApiConnection>();
|
||||||
|
apiConnection.Connection.Returns(connection);
|
||||||
|
var client = new RepositoriesClient(apiConnection);
|
||||||
|
|
||||||
|
var result = await client.AreVulnerabilityAlertsEnabled("owner", "name");
|
||||||
|
|
||||||
|
Assert.Equal(expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task ThrowsExceptionForInvalidStatusCode()
|
||||||
|
{
|
||||||
|
var response = CreateResponse(HttpStatusCode.Conflict);
|
||||||
|
var responseTask = Task.FromResult<IApiResponse<object>>(new ApiResponse<object>(response));
|
||||||
|
var connection = Substitute.For<IConnection>();
|
||||||
|
connection.Get<object>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/name/vulnerability-alerts"),
|
||||||
|
null, null).Returns(responseTask);
|
||||||
|
var apiConnection = Substitute.For<IApiConnection>();
|
||||||
|
apiConnection.Connection.Returns(connection);
|
||||||
|
var client = new RepositoriesClient(apiConnection);
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<ApiException>(() => client.AreVulnerabilityAlertsEnabled("owner", "name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task EnsuresNonNullArguments()
|
||||||
|
{
|
||||||
|
var connection = Substitute.For<IApiConnection>();
|
||||||
|
var client = new RepositoriesClient(connection);
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<ArgumentNullException>(() => client.AreVulnerabilityAlertsEnabled(null, "name"));
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(() => client.AreVulnerabilityAlertsEnabled("", "name"));
|
||||||
|
await Assert.ThrowsAsync<ArgumentNullException>(() => client.AreVulnerabilityAlertsEnabled( "owner", null));
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(() => client.AreVulnerabilityAlertsEnabled("owner", ""));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class TheDeleteMethod
|
public class TheDeleteMethod
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reactive.Linq;
|
using System.Reactive.Linq;
|
||||||
|
using System.Reactive.Threading.Tasks;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NSubstitute;
|
using NSubstitute;
|
||||||
using Octokit.Internal;
|
using Octokit.Internal;
|
||||||
@@ -89,6 +90,30 @@ namespace Octokit.Tests.Reactive
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class TheIsFollowingMethod
|
||||||
|
{
|
||||||
|
[Fact]
|
||||||
|
public void CallsIntoClient()
|
||||||
|
{
|
||||||
|
var githubClient = Substitute.For<IGitHubClient>();
|
||||||
|
var client = new ObservableRepositoriesClient(githubClient);
|
||||||
|
|
||||||
|
client.AreVulnerabilityAlertsEnabled("owner", "name");
|
||||||
|
githubClient.Repository.Received().AreVulnerabilityAlertsEnabled("owner", "name");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task EnsuresNonNullArguments()
|
||||||
|
{
|
||||||
|
var client = new ObservableRepositoriesClient(Substitute.For<IGitHubClient>());
|
||||||
|
|
||||||
|
await Assert.ThrowsAsync<ArgumentNullException>(() => client.AreVulnerabilityAlertsEnabled(null, "name").ToTask());
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(() => client.AreVulnerabilityAlertsEnabled("", "name").ToTask());
|
||||||
|
await Assert.ThrowsAsync<ArgumentNullException>(() => client.AreVulnerabilityAlertsEnabled("owner", null).ToTask());
|
||||||
|
await Assert.ThrowsAsync<ArgumentException>(() => client.AreVulnerabilityAlertsEnabled("owner", "").ToTask());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public class TheDeleteMethod
|
public class TheDeleteMethod
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|||||||
@@ -133,6 +133,17 @@ namespace Octokit
|
|||||||
/// <returns>A <see cref="Repository"/></returns>
|
/// <returns>A <see cref="Repository"/></returns>
|
||||||
Task<Repository> Transfer(long repositoryId, RepositoryTransfer repositoryTransfer);
|
Task<Repository> Transfer(long repositoryId, RepositoryTransfer repositoryTransfer);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if vulnerability alerts are enabled for the specified repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// See the <a href="https://docs.github.com/en/rest/reference/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository">API documentation</a> for more information.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="owner">The current owner of the repository</param>
|
||||||
|
/// <param name="name">The name of the repository</param>
|
||||||
|
/// <returns>A <c>bool</c> indicating if alerts are turned on or not.</returns>
|
||||||
|
Task<bool> AreVulnerabilityAlertsEnabled(string owner, string name);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the specified repository.
|
/// Gets the specified repository.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -229,6 +229,32 @@ namespace Octokit
|
|||||||
return ApiConnection.Post<Repository>(ApiUrls.RepositoryTransfer(repositoryId), repositoryTransfer);
|
return ApiConnection.Post<Repository>(ApiUrls.RepositoryTransfer(repositoryId), repositoryTransfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if vulnerability alerts are enabled for the specified repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// See the <a href="https://docs.github.com/en/rest/reference/repos#check-if-vulnerability-alerts-are-enabled-for-a-repository">API documentation</a> for more information.
|
||||||
|
/// </remarks>
|
||||||
|
/// <param name="owner">The current owner of the repository</param>
|
||||||
|
/// <param name="name">The name of the repository</param>
|
||||||
|
/// <returns>A <c>bool</c> indicating if alerts are turned on or not.</returns>
|
||||||
|
[ManualRoute("GET", "/repos/{owner}/{repo}/vulnerability-alerts")]
|
||||||
|
public async Task<bool> AreVulnerabilityAlertsEnabled(string owner, string name)
|
||||||
|
{
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner));
|
||||||
|
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name));
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var response = await Connection.Get<object>(ApiUrls.RepositoryVulnerabilityAlerts(owner, name), null, null).ConfigureAwait(false);
|
||||||
|
return response.HttpResponse.IsTrue();
|
||||||
|
}
|
||||||
|
catch (NotFoundException)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the specified repository with the values given in <paramref name="update"/>
|
/// Updates the specified repository with the values given in <paramref name="update"/>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -2255,6 +2255,17 @@ namespace Octokit
|
|||||||
return "repos/{0}/{1}/keys".FormatUri(owner, name);
|
return "repos/{0}/{1}/keys".FormatUri(owner, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the <see cref="Uri"/> for checking vulnerability alerts for a repository.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="owner"></param>
|
||||||
|
/// <param name="name"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static Uri RepositoryVulnerabilityAlerts(string owner, string name)
|
||||||
|
{
|
||||||
|
return "repos/{0}/{1}/vulnerability-alerts".FormatUri(owner, name);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the <see cref="System.Uri"/> for the Deployments API for the given repository.
|
/// Returns the <see cref="System.Uri"/> for the Deployments API for the given repository.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user