@@ -984,6 +984,122 @@ def retry_build(
984
984
# Done; return the response.
985
985
return response
986
986
987
+ def approve_build (
988
+ self ,
989
+ request : cloudbuild .ApproveBuildRequest = None ,
990
+ * ,
991
+ name : str = None ,
992
+ approval_result : cloudbuild .ApprovalResult = None ,
993
+ retry : retries .Retry = gapic_v1 .method .DEFAULT ,
994
+ timeout : float = None ,
995
+ metadata : Sequence [Tuple [str , str ]] = (),
996
+ ) -> operation .Operation :
997
+ r"""Approves or rejects a pending build.
998
+ If approved, the returned LRO will be analogous to the
999
+ LRO returned from a CreateBuild call.
1000
+
1001
+ If rejected, the returned LRO will be immediately done.
1002
+
1003
+ Args:
1004
+ request (google.cloud.devtools.cloudbuild_v1.types.ApproveBuildRequest):
1005
+ The request object. Request to approve or reject a
1006
+ pending build.
1007
+ name (str):
1008
+ Required. Name of the target build. For example:
1009
+ "projects/{$project_id}/builds/{$build_id}"
1010
+
1011
+ This corresponds to the ``name`` field
1012
+ on the ``request`` instance; if ``request`` is provided, this
1013
+ should not be set.
1014
+ approval_result (google.cloud.devtools.cloudbuild_v1.types.ApprovalResult):
1015
+ Approval decision and metadata.
1016
+ This corresponds to the ``approval_result`` field
1017
+ on the ``request`` instance; if ``request`` is provided, this
1018
+ should not be set.
1019
+ retry (google.api_core.retry.Retry): Designation of what errors, if any,
1020
+ should be retried.
1021
+ timeout (float): The timeout for this request.
1022
+ metadata (Sequence[Tuple[str, str]]): Strings which should be
1023
+ sent along with the request as metadata.
1024
+
1025
+ Returns:
1026
+ google.api_core.operation.Operation:
1027
+ An object representing a long-running operation.
1028
+
1029
+ The result type for the operation will be
1030
+ :class:`google.cloud.devtools.cloudbuild_v1.types.Build` A
1031
+ build resource in the Cloud Build API.
1032
+
1033
+ At a high level, a Build describes where to find
1034
+ source code, how to build it (for example, the
1035
+ builder image to run on the source), and where to
1036
+ store the built artifacts.
1037
+
1038
+ Fields can include the following variables, which
1039
+ will be expanded when the build is created:
1040
+
1041
+ - $PROJECT_ID: the project ID of the build.
1042
+ - $PROJECT_NUMBER: the project number of the build.
1043
+ - $BUILD_ID: the autogenerated ID of the build.
1044
+ - $REPO_NAME: the source repository name specified
1045
+ by RepoSource.
1046
+ - $BRANCH_NAME: the branch name specified by
1047
+ RepoSource.
1048
+ - $TAG_NAME: the tag name specified by RepoSource.
1049
+ - $REVISION_ID or $COMMIT_SHA: the commit SHA
1050
+ specified by RepoSource or resolved from the
1051
+ specified branch or tag.
1052
+ - $SHORT_SHA: first 7 characters of $REVISION_ID or
1053
+ $COMMIT_SHA.
1054
+
1055
+ """
1056
+ # Create or coerce a protobuf request object.
1057
+ # Sanity check: If we got a request object, we should *not* have
1058
+ # gotten any keyword arguments that map to the request.
1059
+ has_flattened_params = any ([name , approval_result ])
1060
+ if request is not None and has_flattened_params :
1061
+ raise ValueError (
1062
+ "If the `request` argument is set, then none of "
1063
+ "the individual field arguments should be set."
1064
+ )
1065
+
1066
+ # Minor optimization to avoid making a copy if the user passes
1067
+ # in a cloudbuild.ApproveBuildRequest.
1068
+ # There's no risk of modifying the input as we've already verified
1069
+ # there are no flattened fields.
1070
+ if not isinstance (request , cloudbuild .ApproveBuildRequest ):
1071
+ request = cloudbuild .ApproveBuildRequest (request )
1072
+ # If we have keyword arguments corresponding to fields on the
1073
+ # request, apply these.
1074
+ if name is not None :
1075
+ request .name = name
1076
+ if approval_result is not None :
1077
+ request .approval_result = approval_result
1078
+
1079
+ # Wrap the RPC method; this adds retry and timeout information,
1080
+ # and friendly error handling.
1081
+ rpc = self ._transport ._wrapped_methods [self ._transport .approve_build ]
1082
+
1083
+ # Certain fields should be provided within the metadata header;
1084
+ # add these here.
1085
+ metadata = tuple (metadata ) + (
1086
+ gapic_v1 .routing_header .to_grpc_metadata ((("name" , request .name ),)),
1087
+ )
1088
+
1089
+ # Send the request.
1090
+ response = rpc (request , retry = retry , timeout = timeout , metadata = metadata ,)
1091
+
1092
+ # Wrap the response in an operation future.
1093
+ response = operation .from_gapic (
1094
+ response ,
1095
+ self ._transport .operations_client ,
1096
+ cloudbuild .Build ,
1097
+ metadata_type = cloudbuild .BuildOperationMetadata ,
1098
+ )
1099
+
1100
+ # Done; return the response.
1101
+ return response
1102
+
987
1103
def create_build_trigger (
988
1104
self ,
989
1105
request : cloudbuild .CreateBuildTriggerRequest = None ,
0 commit comments