diff --git a/README.md b/README.md index 9e79688..4423a26 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ C# Client for Bitbucket Cloud * [ ] Subject Type * [ ] Pull Requests * [X] Repositories - * [ ] Workspace + * [X] Workspace * [X] Repo Slug * [X] Branch Restrictions * [X] Id @@ -54,11 +54,11 @@ C# Client for Bitbucket Cloud * [X] Key Id * [X] Deployments * [X] Deployment Uuid - * [ ] Deployments Config - * [ ] Environments - * [ ] Environment Uuid - * [ ] Variables - * [ ] Variable Uuid + * [X] Deployments Config + * [X] Environments + * [X] Environment Uuid + * [X] Variables + * [X] Variable Uuid * [X] Diff * [X] Spec * [X] Diffstat diff --git a/src/Bitbucket.Cloud.Net/Bitbucket.Cloud.Net.csproj b/src/Bitbucket.Cloud.Net/Bitbucket.Cloud.Net.csproj index b154e39..9a68e00 100644 --- a/src/Bitbucket.Cloud.Net/Bitbucket.Cloud.Net.csproj +++ b/src/Bitbucket.Cloud.Net/Bitbucket.Cloud.Net.csproj @@ -19,7 +19,6 @@ - diff --git a/src/Bitbucket.Cloud.Net/v2/Repositories/DeploymentsConfig/BitbucketCloudClient.cs b/src/Bitbucket.Cloud.Net/v2/Repositories/DeploymentsConfig/BitbucketCloudClient.cs new file mode 100644 index 0000000..d8ecb77 --- /dev/null +++ b/src/Bitbucket.Cloud.Net/v2/Repositories/DeploymentsConfig/BitbucketCloudClient.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using Bitbucket.Cloud.Net.Common.Models; +using Bitbucket.Cloud.Net.Models; +using Flurl.Http; + +// ReSharper disable once CheckNamespace +namespace Bitbucket.Cloud.Net +{ + public partial class BitbucketCloudClient + { + private IFlurlRequest GetDeploymentsConfigUrl(string workspaceId, string repositorySlug) => GetBaseUrl($"2.0/repositories/{workspaceId}/{repositorySlug}/deployments_config"); + + private IFlurlRequest GetDeploymentsConfigUrl(string workspaceId, string repositorySlug, string path) => GetDeploymentsConfigUrl(workspaceId, repositorySlug) + .AppendPathSegment(path); + + public async Task CreateRepositoryDeploymentsConfigVariableAsync(string workspaceId, string repositorySlug, Guid environmentUuid, Variable variable) + { + var response = await GetDeploymentsConfigUrl(workspaceId, repositorySlug, $"/environments/{environmentUuid:B}/variables") + .PostJsonAsync(variable) + .ConfigureAwait(false); + + return await HandleResponseAsync(response).ConfigureAwait(false); + } + + public async Task> GetRepositoryDeploymentsConfigVariablesAsync(string workspaceId, string repositorySlug, Guid environmentUuid, int? maxPages = null) + { + var queryParamValues = new Dictionary(); + + return await GetPagedResultsAsync(maxPages, queryParamValues, async qpv => + await GetDeploymentsConfigUrl(workspaceId, repositorySlug, $"/environments/{environmentUuid:B}/variables") + .SetQueryParams(qpv) + .GetJsonAsync>() + .ConfigureAwait(false)) + .ConfigureAwait(false); + } + + public async Task UpdateRepositoryDeploymentsConfigVariableAsync(string workspaceId, string repositorySlug, Guid environmentUuid, Guid variableUuid, Variable variable) + { + var response = await GetDeploymentsConfigUrl(workspaceId, repositorySlug, $"/environments/{environmentUuid:B}/variables/{variableUuid:B}") + .PutJsonAsync(variable) + .ConfigureAwait(false); + + return await HandleResponseAsync(response).ConfigureAwait(false); + } + + public async Task DeleteRepositoryDeploymentsConfigVariableAsync(string workspaceId, string repositorySlug, Guid environmentUuid, Guid variableUuid) + { + var response = await GetDeploymentsConfigUrl(workspaceId, repositorySlug, $"/environments/{environmentUuid:B}/variables/{variableUuid:B}") + .DeleteAsync() + .ConfigureAwait(false); + + return await HandleResponseAsync(response).ConfigureAwait(false); + } + } +} diff --git a/test/Bitbucket.Cloud.Net.Tests/Bitbucket.Cloud.Net.Tests.csproj b/test/Bitbucket.Cloud.Net.Tests/Bitbucket.Cloud.Net.Tests.csproj index 41dd459..a5742fe 100644 --- a/test/Bitbucket.Cloud.Net.Tests/Bitbucket.Cloud.Net.Tests.csproj +++ b/test/Bitbucket.Cloud.Net.Tests/Bitbucket.Cloud.Net.Tests.csproj @@ -26,7 +26,6 @@ -