Skip to content

Commit

Permalink
support repositories/deployments_config
Browse files Browse the repository at this point in the history
  • Loading branch information
lvermeulen committed Feb 15, 2020
1 parent 61ac6b1 commit be23086
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Bitbucket.Cloud.Net/Bitbucket.Cloud.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

<ItemGroup>
<Folder Include="v1\" />
<Folder Include="v2\Repositories\DeploymentsConfig\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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<Variable> 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<Variable>(response).ConfigureAwait(false);
}

public async Task<IEnumerable<Variable>> GetRepositoryDeploymentsConfigVariablesAsync(string workspaceId, string repositorySlug, Guid environmentUuid, int? maxPages = null)
{
var queryParamValues = new Dictionary<string, object>();

return await GetPagedResultsAsync(maxPages, queryParamValues, async qpv =>
await GetDeploymentsConfigUrl(workspaceId, repositorySlug, $"/environments/{environmentUuid:B}/variables")
.SetQueryParams(qpv)
.GetJsonAsync<PagedResults<Variable>>()
.ConfigureAwait(false))
.ConfigureAwait(false);
}

public async Task<Variable> 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<Variable>(response).ConfigureAwait(false);
}

public async Task<bool> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

<ItemGroup>
<Folder Include="v1\" />
<Folder Include="v2\Repositories\DeploymentsConfig\" />
</ItemGroup>

</Project>

0 comments on commit be23086

Please sign in to comment.