Skip to content

Commit

Permalink
feat: Add ability to configure BuildTriggers to create Builds that re…
Browse files Browse the repository at this point in the history
…quire approval before executing and ApproveBuild API to approve or reject pending Builds

Comitter: @joonlim
PiperOrigin-RevId: 391072303

Source-Author: Google APIs <noreply@google.com>
Source-Date: Mon Aug 16 10:03:45 2021 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 7fec72948d74c8b25c837e9acb7f3e357c902ad1
Source-Link: googleapis/googleapis@7fec729
  • Loading branch information
yoshi-automation authored and jskeet committed Aug 17, 2021
1 parent d14cf02 commit 26753cf
Show file tree
Hide file tree
Showing 7 changed files with 2,133 additions and 514 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,134 @@ public async Task RetryBuildAsync()
// End snippet
}

/// <summary>Snippet for ApproveBuild</summary>
public void ApproveBuildRequestObject()
{
// Snippet: ApproveBuild(ApproveBuildRequest, CallSettings)
// Create client
CloudBuildClient cloudBuildClient = CloudBuildClient.Create();
// Initialize request argument(s)
ApproveBuildRequest request = new ApproveBuildRequest
{
Name = "",
ApprovalResult = new ApprovalResult(),
};
// Make the request
Operation<Build, BuildOperationMetadata> response = cloudBuildClient.ApproveBuild(request);

// Poll until the returned long-running operation is complete
Operation<Build, BuildOperationMetadata> completedResponse = response.PollUntilCompleted();
// Retrieve the operation result
Build result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Build, BuildOperationMetadata> retrievedResponse = cloudBuildClient.PollOnceApproveBuild(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Build retrievedResult = retrievedResponse.Result;
}
// End snippet
}

/// <summary>Snippet for ApproveBuildAsync</summary>
public async Task ApproveBuildRequestObjectAsync()
{
// Snippet: ApproveBuildAsync(ApproveBuildRequest, CallSettings)
// Additional: ApproveBuildAsync(ApproveBuildRequest, CancellationToken)
// Create client
CloudBuildClient cloudBuildClient = await CloudBuildClient.CreateAsync();
// Initialize request argument(s)
ApproveBuildRequest request = new ApproveBuildRequest
{
Name = "",
ApprovalResult = new ApprovalResult(),
};
// Make the request
Operation<Build, BuildOperationMetadata> response = await cloudBuildClient.ApproveBuildAsync(request);

// Poll until the returned long-running operation is complete
Operation<Build, BuildOperationMetadata> completedResponse = await response.PollUntilCompletedAsync();
// Retrieve the operation result
Build result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Build, BuildOperationMetadata> retrievedResponse = await cloudBuildClient.PollOnceApproveBuildAsync(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Build retrievedResult = retrievedResponse.Result;
}
// End snippet
}

/// <summary>Snippet for ApproveBuild</summary>
public void ApproveBuild()
{
// Snippet: ApproveBuild(string, ApprovalResult, CallSettings)
// Create client
CloudBuildClient cloudBuildClient = CloudBuildClient.Create();
// Initialize request argument(s)
string name = "";
ApprovalResult approvalResult = new ApprovalResult();
// Make the request
Operation<Build, BuildOperationMetadata> response = cloudBuildClient.ApproveBuild(name, approvalResult);

// Poll until the returned long-running operation is complete
Operation<Build, BuildOperationMetadata> completedResponse = response.PollUntilCompleted();
// Retrieve the operation result
Build result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Build, BuildOperationMetadata> retrievedResponse = cloudBuildClient.PollOnceApproveBuild(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Build retrievedResult = retrievedResponse.Result;
}
// End snippet
}

/// <summary>Snippet for ApproveBuildAsync</summary>
public async Task ApproveBuildAsync()
{
// Snippet: ApproveBuildAsync(string, ApprovalResult, CallSettings)
// Additional: ApproveBuildAsync(string, ApprovalResult, CancellationToken)
// Create client
CloudBuildClient cloudBuildClient = await CloudBuildClient.CreateAsync();
// Initialize request argument(s)
string name = "";
ApprovalResult approvalResult = new ApprovalResult();
// Make the request
Operation<Build, BuildOperationMetadata> response = await cloudBuildClient.ApproveBuildAsync(name, approvalResult);

// Poll until the returned long-running operation is complete
Operation<Build, BuildOperationMetadata> completedResponse = await response.PollUntilCompletedAsync();
// Retrieve the operation result
Build result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<Build, BuildOperationMetadata> retrievedResponse = await cloudBuildClient.PollOnceApproveBuildAsync(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
Build retrievedResult = retrievedResponse.Result;
}
// End snippet
}

/// <summary>Snippet for CreateBuildTrigger</summary>
public void CreateBuildTriggerRequestObject()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void GetBuildRequestObject()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -79,6 +79,7 @@ public void GetBuildRequestObject()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down Expand Up @@ -108,7 +109,7 @@ public void GetBuildRequestObject()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -143,6 +144,7 @@ public void GetBuildRequestObject()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down Expand Up @@ -173,7 +175,7 @@ public void GetBuild()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -208,6 +210,7 @@ public void GetBuild()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down Expand Up @@ -236,7 +239,7 @@ public void GetBuild()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -271,6 +274,7 @@ public void GetBuild()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down Expand Up @@ -302,7 +306,7 @@ public void CancelBuildRequestObject()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -337,6 +341,7 @@ public void CancelBuildRequestObject()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down Expand Up @@ -366,7 +371,7 @@ public void CancelBuildRequestObject()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -401,6 +406,7 @@ public void CancelBuildRequestObject()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down Expand Up @@ -431,7 +437,7 @@ public void CancelBuild()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -466,6 +472,7 @@ public void CancelBuild()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down Expand Up @@ -494,7 +501,7 @@ public void CancelBuild()
Build expectedResponse = new Build
{
Id = "id74b70bb8",
Status = Build.Types.Status.InternalError,
Status = Build.Types.Status.Success,
Source = new Source(),
CreateTime = new wkt::Timestamp(),
StartTime = new wkt::Timestamp(),
Expand Down Expand Up @@ -529,6 +536,7 @@ public void CancelBuild()
Artifacts = new Artifacts(),
QueueTtl = new wkt::Duration(),
ServiceAccountAsServiceAccountName = ServiceAccountName.FromProjectServiceAccount("[PROJECT]", "[SERVICE_ACCOUNT]"),
Approval = new BuildApproval(),
BuildName = BuildName.FromProjectBuild("[PROJECT]", "[BUILD]"),
AvailableSecrets = new Secrets(),
Warnings =
Expand Down
Loading

0 comments on commit 26753cf

Please sign in to comment.