Skip to content
Permalink
Browse files
feat: Add ability to configure BuildTriggers to create Builds that re…
…quire approval before executing and ApproveBuild API to approve or reject pending Builds (#574)

Comitter: @joonlim
PiperOrigin-RevId: 391072303

Source-Link: googleapis/googleapis@7fec729

Source-Link: https://github.com/googleapis/googleapis-gen/commit/22f5dc30b16225014527e354cc2cf0f00ff5c120
  • Loading branch information
gcf-owl-bot[bot] committed Aug 20, 2021
1 parent 2d7bd7d commit 1e19e5adbe845c47b4b3d00e91f349a7b780142b
Show file tree
Hide file tree
Showing 21 changed files with 6,474 additions and 432 deletions.
@@ -29,6 +29,8 @@
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.devtools.cloudbuild.v1.stub.CloudBuildStub;
import com.google.cloud.devtools.cloudbuild.v1.stub.CloudBuildStubSettings;
import com.google.cloudbuild.v1.ApprovalResult;
import com.google.cloudbuild.v1.ApproveBuildRequest;
import com.google.cloudbuild.v1.Build;
import com.google.cloudbuild.v1.BuildOperationMetadata;
import com.google.cloudbuild.v1.BuildTrigger;
@@ -818,6 +820,121 @@ public final UnaryCallable<RetryBuildRequest, Operation> retryBuildCallable() {
return stub.retryBuildCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Approves or rejects a pending build.
*
* <p>If approved, the returned LRO will be analogous to the LRO returned from a CreateBuild call.
*
* <p>If rejected, the returned LRO will be immediately done.
*
* <p>Sample code:
*
* <pre>{@code
* try (CloudBuildClient cloudBuildClient = CloudBuildClient.create()) {
* String name = "name3373707";
* ApprovalResult approvalResult = ApprovalResult.newBuilder().build();
* Build response = cloudBuildClient.approveBuildAsync(name, approvalResult).get();
* }
* }</pre>
*
* @param name Required. Name of the target build. For example:
* "projects/{$project_id}/builds/{$build_id}"
* @param approvalResult Approval decision and metadata.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Build, BuildOperationMetadata> approveBuildAsync(
String name, ApprovalResult approvalResult) {
ApproveBuildRequest request =
ApproveBuildRequest.newBuilder().setName(name).setApprovalResult(approvalResult).build();
return approveBuildAsync(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Approves or rejects a pending build.
*
* <p>If approved, the returned LRO will be analogous to the LRO returned from a CreateBuild call.
*
* <p>If rejected, the returned LRO will be immediately done.
*
* <p>Sample code:
*
* <pre>{@code
* try (CloudBuildClient cloudBuildClient = CloudBuildClient.create()) {
* ApproveBuildRequest request =
* ApproveBuildRequest.newBuilder()
* .setName("name3373707")
* .setApprovalResult(ApprovalResult.newBuilder().build())
* .build();
* Build response = cloudBuildClient.approveBuildAsync(request).get();
* }
* }</pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.rpc.ApiException if the remote call fails
*/
public final OperationFuture<Build, BuildOperationMetadata> approveBuildAsync(
ApproveBuildRequest request) {
return approveBuildOperationCallable().futureCall(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Approves or rejects a pending build.
*
* <p>If approved, the returned LRO will be analogous to the LRO returned from a CreateBuild call.
*
* <p>If rejected, the returned LRO will be immediately done.
*
* <p>Sample code:
*
* <pre>{@code
* try (CloudBuildClient cloudBuildClient = CloudBuildClient.create()) {
* ApproveBuildRequest request =
* ApproveBuildRequest.newBuilder()
* .setName("name3373707")
* .setApprovalResult(ApprovalResult.newBuilder().build())
* .build();
* OperationFuture<Build, BuildOperationMetadata> future =
* cloudBuildClient.approveBuildOperationCallable().futureCall(request);
* // Do something.
* Build response = future.get();
* }
* }</pre>
*/
public final OperationCallable<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationCallable() {
return stub.approveBuildOperationCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Approves or rejects a pending build.
*
* <p>If approved, the returned LRO will be analogous to the LRO returned from a CreateBuild call.
*
* <p>If rejected, the returned LRO will be immediately done.
*
* <p>Sample code:
*
* <pre>{@code
* try (CloudBuildClient cloudBuildClient = CloudBuildClient.create()) {
* ApproveBuildRequest request =
* ApproveBuildRequest.newBuilder()
* .setName("name3373707")
* .setApprovalResult(ApprovalResult.newBuilder().build())
* .build();
* ApiFuture<Operation> future = cloudBuildClient.approveBuildCallable().futureCall(request);
* // Do something.
* Operation response = future.get();
* }
* }</pre>
*/
public final UnaryCallable<ApproveBuildRequest, Operation> approveBuildCallable() {
return stub.approveBuildCallable();
}

// AUTO-GENERATED DOCUMENTATION AND METHOD.
/**
* Creates a new `BuildTrigger`.
@@ -33,6 +33,7 @@
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.cloud.devtools.cloudbuild.v1.stub.CloudBuildStubSettings;
import com.google.cloudbuild.v1.ApproveBuildRequest;
import com.google.cloudbuild.v1.Build;
import com.google.cloudbuild.v1.BuildOperationMetadata;
import com.google.cloudbuild.v1.BuildTrigger;
@@ -139,6 +140,17 @@ public UnaryCallSettings<RetryBuildRequest, Operation> retryBuildSettings() {
return ((CloudBuildStubSettings) getStubSettings()).retryBuildOperationSettings();
}

/** Returns the object with the settings used for calls to approveBuild. */
public UnaryCallSettings<ApproveBuildRequest, Operation> approveBuildSettings() {
return ((CloudBuildStubSettings) getStubSettings()).approveBuildSettings();
}

/** Returns the object with the settings used for calls to approveBuild. */
public OperationCallSettings<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationSettings() {
return ((CloudBuildStubSettings) getStubSettings()).approveBuildOperationSettings();
}

/** Returns the object with the settings used for calls to createBuildTrigger. */
public UnaryCallSettings<CreateBuildTriggerRequest, BuildTrigger> createBuildTriggerSettings() {
return ((CloudBuildStubSettings) getStubSettings()).createBuildTriggerSettings();
@@ -364,6 +376,17 @@ public UnaryCallSettings.Builder<RetryBuildRequest, Operation> retryBuildSetting
return getStubSettingsBuilder().retryBuildOperationSettings();
}

/** Returns the builder for the settings used for calls to approveBuild. */
public UnaryCallSettings.Builder<ApproveBuildRequest, Operation> approveBuildSettings() {
return getStubSettingsBuilder().approveBuildSettings();
}

/** Returns the builder for the settings used for calls to approveBuild. */
public OperationCallSettings.Builder<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationSettings() {
return getStubSettingsBuilder().approveBuildOperationSettings();
}

/** Returns the builder for the settings used for calls to createBuildTrigger. */
public UnaryCallSettings.Builder<CreateBuildTriggerRequest, BuildTrigger>
createBuildTriggerSettings() {
@@ -10,6 +10,9 @@
"grpc": {
"libraryClient": "CloudBuildClient",
"rpcs": {
"ApproveBuild": {
"methods": ["approveBuildAsync", "approveBuildAsync", "approveBuildOperationCallable", "approveBuildCallable"]
},
"CancelBuild": {
"methods": ["cancelBuild", "cancelBuild", "cancelBuildCallable"]
},
@@ -23,6 +23,7 @@
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloudbuild.v1.ApproveBuildRequest;
import com.google.cloudbuild.v1.Build;
import com.google.cloudbuild.v1.BuildOperationMetadata;
import com.google.cloudbuild.v1.BuildTrigger;
@@ -103,6 +104,15 @@ public UnaryCallable<RetryBuildRequest, Operation> retryBuildCallable() {
throw new UnsupportedOperationException("Not implemented: retryBuildCallable()");
}

public OperationCallable<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationCallable() {
throw new UnsupportedOperationException("Not implemented: approveBuildOperationCallable()");
}

public UnaryCallable<ApproveBuildRequest, Operation> approveBuildCallable() {
throw new UnsupportedOperationException("Not implemented: approveBuildCallable()");
}

public UnaryCallable<CreateBuildTriggerRequest, BuildTrigger> createBuildTriggerCallable() {
throw new UnsupportedOperationException("Not implemented: createBuildTriggerCallable()");
}
@@ -46,6 +46,7 @@
import com.google.api.gax.rpc.TransportChannelProvider;
import com.google.api.gax.rpc.UnaryCallSettings;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloudbuild.v1.ApproveBuildRequest;
import com.google.cloudbuild.v1.Build;
import com.google.cloudbuild.v1.BuildOperationMetadata;
import com.google.cloudbuild.v1.BuildTrigger;
@@ -132,6 +133,9 @@ public class CloudBuildStubSettings extends StubSettings<CloudBuildStubSettings>
private final UnaryCallSettings<RetryBuildRequest, Operation> retryBuildSettings;
private final OperationCallSettings<RetryBuildRequest, Build, BuildOperationMetadata>
retryBuildOperationSettings;
private final UnaryCallSettings<ApproveBuildRequest, Operation> approveBuildSettings;
private final OperationCallSettings<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationSettings;
private final UnaryCallSettings<CreateBuildTriggerRequest, BuildTrigger>
createBuildTriggerSettings;
private final UnaryCallSettings<GetBuildTriggerRequest, BuildTrigger> getBuildTriggerSettings;
@@ -371,6 +375,17 @@ public UnaryCallSettings<RetryBuildRequest, Operation> retryBuildSettings() {
return retryBuildOperationSettings;
}

/** Returns the object with the settings used for calls to approveBuild. */
public UnaryCallSettings<ApproveBuildRequest, Operation> approveBuildSettings() {
return approveBuildSettings;
}

/** Returns the object with the settings used for calls to approveBuild. */
public OperationCallSettings<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationSettings() {
return approveBuildOperationSettings;
}

/** Returns the object with the settings used for calls to createBuildTrigger. */
public UnaryCallSettings<CreateBuildTriggerRequest, BuildTrigger> createBuildTriggerSettings() {
return createBuildTriggerSettings;
@@ -543,6 +558,8 @@ protected CloudBuildStubSettings(Builder settingsBuilder) throws IOException {
cancelBuildSettings = settingsBuilder.cancelBuildSettings().build();
retryBuildSettings = settingsBuilder.retryBuildSettings().build();
retryBuildOperationSettings = settingsBuilder.retryBuildOperationSettings().build();
approveBuildSettings = settingsBuilder.approveBuildSettings().build();
approveBuildOperationSettings = settingsBuilder.approveBuildOperationSettings().build();
createBuildTriggerSettings = settingsBuilder.createBuildTriggerSettings().build();
getBuildTriggerSettings = settingsBuilder.getBuildTriggerSettings().build();
listBuildTriggersSettings = settingsBuilder.listBuildTriggersSettings().build();
@@ -575,6 +592,9 @@ public static class Builder extends StubSettings.Builder<CloudBuildStubSettings,
private final UnaryCallSettings.Builder<RetryBuildRequest, Operation> retryBuildSettings;
private final OperationCallSettings.Builder<RetryBuildRequest, Build, BuildOperationMetadata>
retryBuildOperationSettings;
private final UnaryCallSettings.Builder<ApproveBuildRequest, Operation> approveBuildSettings;
private final OperationCallSettings.Builder<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationSettings;
private final UnaryCallSettings.Builder<CreateBuildTriggerRequest, BuildTrigger>
createBuildTriggerSettings;
private final UnaryCallSettings.Builder<GetBuildTriggerRequest, BuildTrigger>
@@ -673,6 +693,8 @@ protected Builder(ClientContext clientContext) {
cancelBuildSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
retryBuildSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
retryBuildOperationSettings = OperationCallSettings.newBuilder();
approveBuildSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
approveBuildOperationSettings = OperationCallSettings.newBuilder();
createBuildTriggerSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
getBuildTriggerSettings = UnaryCallSettings.newUnaryCallSettingsBuilder();
listBuildTriggersSettings = PagedCallSettings.newBuilder(LIST_BUILD_TRIGGERS_PAGE_STR_FACT);
@@ -697,6 +719,7 @@ protected Builder(ClientContext clientContext) {
listBuildsSettings,
cancelBuildSettings,
retryBuildSettings,
approveBuildSettings,
createBuildTriggerSettings,
getBuildTriggerSettings,
listBuildTriggersSettings,
@@ -722,6 +745,8 @@ protected Builder(CloudBuildStubSettings settings) {
cancelBuildSettings = settings.cancelBuildSettings.toBuilder();
retryBuildSettings = settings.retryBuildSettings.toBuilder();
retryBuildOperationSettings = settings.retryBuildOperationSettings.toBuilder();
approveBuildSettings = settings.approveBuildSettings.toBuilder();
approveBuildOperationSettings = settings.approveBuildOperationSettings.toBuilder();
createBuildTriggerSettings = settings.createBuildTriggerSettings.toBuilder();
getBuildTriggerSettings = settings.getBuildTriggerSettings.toBuilder();
listBuildTriggersSettings = settings.listBuildTriggersSettings.toBuilder();
@@ -746,6 +771,7 @@ protected Builder(CloudBuildStubSettings settings) {
listBuildsSettings,
cancelBuildSettings,
retryBuildSettings,
approveBuildSettings,
createBuildTriggerSettings,
getBuildTriggerSettings,
listBuildTriggersSettings,
@@ -799,6 +825,11 @@ private static Builder initDefaults(Builder builder) {
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_1_params"));

builder
.approveBuildSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params"));

builder
.createBuildTriggerSettings()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_1_codes"))
@@ -905,6 +936,30 @@ private static Builder initDefaults(Builder builder) {
.setTotalTimeout(Duration.ofMillis(300000L))
.build()));

builder
.approveBuildOperationSettings()
.setInitialCallSettings(
UnaryCallSettings
.<ApproveBuildRequest, OperationSnapshot>newUnaryCallSettingsBuilder()
.setRetryableCodes(RETRYABLE_CODE_DEFINITIONS.get("no_retry_codes"))
.setRetrySettings(RETRY_PARAM_DEFINITIONS.get("no_retry_params"))
.build())
.setResponseTransformer(
ProtoOperationTransformers.ResponseTransformer.create(Build.class))
.setMetadataTransformer(
ProtoOperationTransformers.MetadataTransformer.create(BuildOperationMetadata.class))
.setPollingAlgorithm(
OperationTimedPollAlgorithm.create(
RetrySettings.newBuilder()
.setInitialRetryDelay(Duration.ofMillis(5000L))
.setRetryDelayMultiplier(1.5)
.setMaxRetryDelay(Duration.ofMillis(45000L))
.setInitialRpcTimeout(Duration.ZERO)
.setRpcTimeoutMultiplier(1.0)
.setMaxRpcTimeout(Duration.ZERO)
.setTotalTimeout(Duration.ofMillis(300000L))
.build()));

builder
.runBuildTriggerOperationSettings()
.setInitialCallSettings(
@@ -1064,6 +1119,19 @@ public UnaryCallSettings.Builder<RetryBuildRequest, Operation> retryBuildSetting
return retryBuildOperationSettings;
}

/** Returns the builder for the settings used for calls to approveBuild. */
public UnaryCallSettings.Builder<ApproveBuildRequest, Operation> approveBuildSettings() {
return approveBuildSettings;
}

/** Returns the builder for the settings used for calls to approveBuild. */
@BetaApi(
"The surface for use by generated code is not stable yet and may change in the future.")
public OperationCallSettings.Builder<ApproveBuildRequest, Build, BuildOperationMetadata>
approveBuildOperationSettings() {
return approveBuildOperationSettings;
}

/** Returns the builder for the settings used for calls to createBuildTrigger. */
public UnaryCallSettings.Builder<CreateBuildTriggerRequest, BuildTrigger>
createBuildTriggerSettings() {

0 comments on commit 1e19e5a

Please sign in to comment.