-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat]: Added Environments API - GetAll list only feature
- Loading branch information
Showing
13 changed files
with
606 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Octokit.Reactive/Clients/IObservableRepositoryDeployEnvironmentsClient.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using Octokit.Models.Response; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Octokit.Reactive | ||
{ | ||
public interface IObservableRepositoryDeployEnvironmentsClient | ||
{ | ||
/// <summary> | ||
/// Gets all the environments for the specified repository. Any user with pull access | ||
/// to a repository can view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// https://docs.github.com/en/rest/deployments/environments#list-environments | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
IObservable<DeploymentEnvironmentsResponse> GetAll(string owner, string name); | ||
|
||
/// <summary> | ||
/// Gets all the environments for the specified repository. Any user with pull access | ||
/// to a repository can view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// https://docs.github.com/en/rest/deployments/environments#list-environments | ||
/// </remarks> | ||
/// <param name="repositoryId">The Id of the repository</param> | ||
IObservable<DeploymentEnvironmentsResponse> GetAll(long repositoryId); | ||
|
||
|
||
/// <summary> | ||
/// Gets all the environments for the specified repository. Any user with pull access | ||
/// to a repository can view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// https://docs.github.com/en/rest/deployments/environments#list-environments | ||
/// </remarks> | ||
/// <param name="owner">The owner of the repository</param> | ||
/// <param name="name">The name of the repository</param> | ||
/// <param name="options">Paging options</param> | ||
IObservable<DeploymentEnvironmentsResponse> GetAll(string owner, string name, ApiOptions options); | ||
|
||
|
||
/// <summary> | ||
/// Gets all the environments for the specified repository. Any user with pull access | ||
/// to a repository can view deployments. | ||
/// </summary> | ||
/// <remarks> | ||
/// https://docs.github.com/en/rest/deployments/environments#list-environments | ||
/// </remarks> | ||
/// <param name="repositoryId">Repository ID</param> | ||
/// <param name="options">Paging options</param> | ||
IObservable<DeploymentEnvironmentsResponse> GetAll(long repositoryId, ApiOptions options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Reactive.Threading.Tasks; | ||
using Octokit.Models.Response; | ||
using Octokit.Reactive.Internal; | ||
|
||
namespace Octokit.Reactive.Clients | ||
{ | ||
public class ObservableEnvironmentsClient : IObservableRepositoryDeployEnvironmentsClient | ||
{ | ||
readonly IRepositoryDeployEnvironmentsClient _client; | ||
readonly IConnection _connection; | ||
|
||
public ObservableEnvironmentsClient(IGitHubClient client) | ||
{ | ||
Ensure.ArgumentNotNull(client, nameof(client)); | ||
|
||
_client = client.Repository.Environment; | ||
_connection = client.Connection; | ||
} | ||
|
||
public IObservable<DeploymentEnvironmentsResponse> GetAll(string owner, string name) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); | ||
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); | ||
|
||
return GetAll(owner, name, ApiOptions.None); | ||
} | ||
|
||
public IObservable<DeploymentEnvironmentsResponse> GetAll(long repositoryId) | ||
{ | ||
return GetAll(repositoryId, ApiOptions.None); | ||
} | ||
|
||
public IObservable<DeploymentEnvironmentsResponse> GetAll(string owner, string name, ApiOptions options) | ||
{ | ||
Ensure.ArgumentNotNullOrEmptyString(owner, nameof(owner)); | ||
Ensure.ArgumentNotNullOrEmptyString(name, nameof(name)); | ||
Ensure.ArgumentNotNull(options, nameof(options)); | ||
|
||
return _connection.GetAndFlattenAllPages<DeploymentEnvironmentsResponse>( | ||
ApiUrls.DeploymentEnvironments(owner, name), options); | ||
} | ||
|
||
public IObservable<DeploymentEnvironmentsResponse> GetAll(long repositoryId, ApiOptions options) | ||
{ | ||
Ensure.ArgumentNotNull(options, nameof(options)); | ||
|
||
return _connection.GetAndFlattenAllPages<DeploymentEnvironmentsResponse>( | ||
ApiUrls.DeploymentEnvironments(repositoryId), options); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using Octokit; | ||
using Octokit.Models.Response; | ||
using Octokit.Tests; | ||
using Xunit; | ||
|
||
|
||
namespace Octokit.Tests.Clients | ||
{ | ||
public class EnvironmentsClientTests | ||
{ | ||
public class TheGetAllMethod | ||
{ | ||
const string name = "name"; | ||
const string owner = "owner"; | ||
const long repositoryId = 1; | ||
|
||
[Fact] | ||
public async Task EnsuresNonNullArguments() | ||
{ | ||
var client = new DeploymentEnvironmentsClient(Substitute.For<IApiConnection>()); | ||
|
||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(null, name)); | ||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(owner, null)); | ||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(owner, name, null)); | ||
|
||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAll(repositoryId, null)); | ||
} | ||
|
||
[Fact] | ||
public async Task EnsuresNonEmptyArguments() | ||
{ | ||
var client = new DeploymentEnvironmentsClient(Substitute.For<IApiConnection>()); | ||
|
||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll("", name)); | ||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(owner, "")); | ||
} | ||
|
||
[Theory] | ||
[InlineData(" ")] | ||
[InlineData("\n")] | ||
[InlineData("\t")] | ||
[InlineData(" ")] | ||
[InlineData("\n\r")] | ||
public async Task EnsuresNonWhitespaceArguments(string whitespace) | ||
{ | ||
var client = new DeploymentEnvironmentsClient(Substitute.For<IApiConnection>()); | ||
|
||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(whitespace, name)); | ||
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAll(owner, whitespace)); | ||
} | ||
|
||
[Fact] | ||
public async Task RequestsCorrectUrl() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new DeploymentEnvironmentsClient(connection); | ||
var expectedUrl = string.Format("repos/{0}/{1}/environments", owner, name); | ||
|
||
var res = await client.GetAll(owner, name); | ||
|
||
connection.Received() | ||
.Get<DeploymentEnvironmentsResponse>( | ||
Arg.Is<Uri>(u => u.ToString() == expectedUrl)); | ||
} | ||
|
||
[Fact] | ||
public async Task RequestsCorrectUrlWithRepositoryId() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new DeploymentEnvironmentsClient(connection); | ||
var expectedUrl = string.Format("repositories/{0}/environments", repositoryId); | ||
|
||
await client.GetAll(repositoryId); | ||
|
||
connection.Received() | ||
.Get<DeploymentEnvironmentsResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUrl)); | ||
} | ||
|
||
[Fact] | ||
public async Task RequestsCorrectUrlWithApiOptions() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new DeploymentEnvironmentsClient(connection); | ||
var expectedUrl = string.Format("repos/{0}/{1}/environments", owner, name); | ||
|
||
var options = new ApiOptions | ||
{ | ||
PageSize = 10, | ||
StartPage = 1 | ||
}; | ||
|
||
await client.GetAll(owner, name, options); | ||
|
||
connection.Received() | ||
.Get<DeploymentEnvironmentsResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), | ||
Arg.Is<IDictionary<string, string>>(u => u["per_page"] == "10" && u["page"] == "1")); | ||
} | ||
|
||
[Fact] | ||
public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new DeploymentEnvironmentsClient(connection); | ||
var expectedUrl = string.Format("repositories/{0}/environments", repositoryId); | ||
|
||
var options = new ApiOptions | ||
{ | ||
PageSize = 10, | ||
StartPage = 1 | ||
}; | ||
|
||
await client.GetAll(repositoryId, options); | ||
|
||
connection.Received() | ||
.Get<DeploymentEnvironmentsResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUrl), | ||
Arg.Is<IDictionary<string, string>>(u => u["per_page"] == "10" && u["page"] == "1")); | ||
} | ||
|
||
[Fact] | ||
public void RequestsCorrectUrlWithPreviewAcceptHeaders() | ||
{ | ||
var connection = Substitute.For<IApiConnection>(); | ||
var client = new DeploymentEnvironmentsClient(connection); | ||
var expectedUrl = string.Format("repos/{0}/{1}/environments", owner, name); | ||
|
||
client.GetAll(owner, name); | ||
connection.Received() | ||
.Get<DeploymentEnvironmentsResponse>(Arg.Is<Uri>(u => u.ToString() == expectedUrl)); | ||
} | ||
} | ||
|
||
public class TheCtor | ||
{ | ||
[Fact] | ||
public void EnsuresNonNullArguments() | ||
{ | ||
Assert.Throws<ArgumentNullException>(() => new DeploymentEnvironmentsClient(null)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.