diff --git a/google/cloud/devtools/cloudbuild/__init__.py b/google/cloud/devtools/cloudbuild/__init__.py index febf0d2c..c7c68d8d 100644 --- a/google/cloud/devtools/cloudbuild/__init__.py +++ b/google/cloud/devtools/cloudbuild/__init__.py @@ -81,6 +81,7 @@ from google.cloud.devtools.cloudbuild_v1.types.cloudbuild import ( ReceiveTriggerWebhookResponse, ) +from google.cloud.devtools.cloudbuild_v1.types.cloudbuild import RepositoryEventConfig from google.cloud.devtools.cloudbuild_v1.types.cloudbuild import RepoSource from google.cloud.devtools.cloudbuild_v1.types.cloudbuild import Results from google.cloud.devtools.cloudbuild_v1.types.cloudbuild import RetryBuildRequest @@ -150,6 +151,7 @@ "PushFilter", "ReceiveTriggerWebhookRequest", "ReceiveTriggerWebhookResponse", + "RepositoryEventConfig", "RepoSource", "Results", "RetryBuildRequest", diff --git a/google/cloud/devtools/cloudbuild_v1/__init__.py b/google/cloud/devtools/cloudbuild_v1/__init__.py index e099eba1..c905749d 100644 --- a/google/cloud/devtools/cloudbuild_v1/__init__.py +++ b/google/cloud/devtools/cloudbuild_v1/__init__.py @@ -61,6 +61,7 @@ from .types.cloudbuild import PushFilter from .types.cloudbuild import ReceiveTriggerWebhookRequest from .types.cloudbuild import ReceiveTriggerWebhookResponse +from .types.cloudbuild import RepositoryEventConfig from .types.cloudbuild import RepoSource from .types.cloudbuild import Results from .types.cloudbuild import RetryBuildRequest @@ -127,6 +128,7 @@ "ReceiveTriggerWebhookRequest", "ReceiveTriggerWebhookResponse", "RepoSource", + "RepositoryEventConfig", "Results", "RetryBuildRequest", "RunBuildTriggerRequest", diff --git a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py index a739cb2e..48035506 100644 --- a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py +++ b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/async_client.py @@ -79,6 +79,8 @@ class CloudBuildAsyncClient: parse_crypto_key_path = staticmethod(CloudBuildClient.parse_crypto_key_path) network_path = staticmethod(CloudBuildClient.network_path) parse_network_path = staticmethod(CloudBuildClient.parse_network_path) + repository_path = staticmethod(CloudBuildClient.repository_path) + parse_repository_path = staticmethod(CloudBuildClient.parse_repository_path) secret_version_path = staticmethod(CloudBuildClient.secret_version_path) parse_secret_version_path = staticmethod(CloudBuildClient.parse_secret_version_path) service_account_path = staticmethod(CloudBuildClient.service_account_path) diff --git a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py index 2bfdf68f..c05a99ca 100644 --- a/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py +++ b/google/cloud/devtools/cloudbuild_v1/services/cloud_build/client.py @@ -265,6 +265,30 @@ def parse_network_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def repository_path( + project: str, + location: str, + connection: str, + repository: str, + ) -> str: + """Returns a fully-qualified repository string.""" + return "projects/{project}/locations/{location}/connections/{connection}/repositories/{repository}".format( + project=project, + location=location, + connection=connection, + repository=repository, + ) + + @staticmethod + def parse_repository_path(path: str) -> Dict[str, str]: + """Parses a repository path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/connections/(?P.+?)/repositories/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + @staticmethod def secret_version_path( project: str, diff --git a/google/cloud/devtools/cloudbuild_v1/types/__init__.py b/google/cloud/devtools/cloudbuild_v1/types/__init__.py index 4bc377c0..35b02f9c 100644 --- a/google/cloud/devtools/cloudbuild_v1/types/__init__.py +++ b/google/cloud/devtools/cloudbuild_v1/types/__init__.py @@ -54,6 +54,7 @@ PushFilter, ReceiveTriggerWebhookRequest, ReceiveTriggerWebhookResponse, + RepositoryEventConfig, RepoSource, Results, RetryBuildRequest, @@ -118,6 +119,7 @@ "PushFilter", "ReceiveTriggerWebhookRequest", "ReceiveTriggerWebhookResponse", + "RepositoryEventConfig", "RepoSource", "Results", "RetryBuildRequest", diff --git a/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py b/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py index dba7de3b..52e87889 100644 --- a/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py +++ b/google/cloud/devtools/cloudbuild_v1/types/cloudbuild.py @@ -64,6 +64,7 @@ "ApprovalConfig", "ApprovalResult", "BuildTrigger", + "RepositoryEventConfig", "GitHubEventsConfig", "PubsubConfig", "WebhookConfig", @@ -2195,6 +2196,10 @@ class BuildTrigger(proto.Message): ([PROJECT_NUM]@system.gserviceaccount.com) will be used instead. Format: ``projects/{PROJECT_ID}/serviceAccounts/{ACCOUNT_ID_OR_EMAIL}`` + repository_event_config (google.cloud.devtools.cloudbuild_v1.types.RepositoryEventConfig): + The configuration of a trigger that creates a + build whenever an event from Repo API is + received. """ resource_name: str = proto.Field( @@ -2283,6 +2288,81 @@ class BuildTrigger(proto.Message): proto.STRING, number=33, ) + repository_event_config: "RepositoryEventConfig" = proto.Field( + proto.MESSAGE, + number=39, + message="RepositoryEventConfig", + ) + + +class RepositoryEventConfig(proto.Message): + r"""The configuration of a trigger that creates a build whenever + an event from Repo API is received. + + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + + Attributes: + repository (str): + The resource name of the Repo API resource. + repository_type (google.cloud.devtools.cloudbuild_v1.types.RepositoryEventConfig.RepositoryType): + Output only. The type of the SCM vendor the + repository points to. + pull_request (google.cloud.devtools.cloudbuild_v1.types.PullRequestFilter): + Filter to match changes in pull requests. + + This field is a member of `oneof`_ ``filter``. + push (google.cloud.devtools.cloudbuild_v1.types.PushFilter): + Filter to match changes in refs like + branches, tags. + + This field is a member of `oneof`_ ``filter``. + """ + + class RepositoryType(proto.Enum): + r"""All possible SCM repo types from Repo API. + + Values: + REPOSITORY_TYPE_UNSPECIFIED (0): + If unspecified, RepositoryType defaults to + GITHUB. + GITHUB (1): + The SCM repo is GITHUB. + GITHUB_ENTERPRISE (2): + The SCM repo is GITHUB Enterprise. + GITLAB_ENTERPRISE (3): + The SCM repo is GITLAB Enterprise. + """ + REPOSITORY_TYPE_UNSPECIFIED = 0 + GITHUB = 1 + GITHUB_ENTERPRISE = 2 + GITLAB_ENTERPRISE = 3 + + repository: str = proto.Field( + proto.STRING, + number=1, + ) + repository_type: RepositoryType = proto.Field( + proto.ENUM, + number=2, + enum=RepositoryType, + ) + pull_request: "PullRequestFilter" = proto.Field( + proto.MESSAGE, + number=3, + oneof="filter", + message="PullRequestFilter", + ) + push: "PushFilter" = proto.Field( + proto.MESSAGE, + number=4, + oneof="filter", + message="PushFilter", + ) class GitHubEventsConfig(proto.Message): diff --git a/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v1.json b/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v1.json index 71f6ed56..e379efab 100644 --- a/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v1.json +++ b/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v1.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-build", - "version": "3.16.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v2.json b/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v2.json index 7f7f5fbc..28513727 100644 --- a/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v2.json +++ b/samples/generated_samples/snippet_metadata_google.devtools.cloudbuild.v2.json @@ -8,7 +8,7 @@ ], "language": "PYTHON", "name": "google-cloud-build", - "version": "3.16.0" + "version": "0.1.0" }, "snippets": [ { diff --git a/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py b/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py index e16d6c11..232b3fc9 100644 --- a/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py +++ b/tests/unit/gapic/cloudbuild_v1/test_cloud_build.py @@ -8152,6 +8152,12 @@ def test_create_build_trigger_rest(request_type): "included_files": ["included_files_value1", "included_files_value2"], "filter": "filter_value", "service_account": "service_account_value", + "repository_event_config": { + "repository": "repository_value", + "repository_type": 1, + "pull_request": {}, + "push": {}, + }, } request = request_type(**request_init) @@ -8571,6 +8577,12 @@ def test_create_build_trigger_rest_bad_request( "included_files": ["included_files_value1", "included_files_value2"], "filter": "filter_value", "service_account": "service_account_value", + "repository_event_config": { + "repository": "repository_value", + "repository_type": 1, + "pull_request": {}, + "push": {}, + }, } request = request_type(**request_init) @@ -9786,6 +9798,12 @@ def test_update_build_trigger_rest(request_type): "included_files": ["included_files_value1", "included_files_value2"], "filter": "filter_value", "service_account": "service_account_value", + "repository_event_config": { + "repository": "repository_value", + "repository_type": 1, + "pull_request": {}, + "push": {}, + }, } request = request_type(**request_init) @@ -10208,6 +10226,12 @@ def test_update_build_trigger_rest_bad_request( "included_files": ["included_files_value1", "included_files_value2"], "filter": "filter_value", "service_account": "service_account_value", + "repository_event_config": { + "repository": "repository_value", + "repository_type": 1, + "pull_request": {}, + "push": {}, + }, } request = request_type(**request_init) @@ -13057,10 +13081,39 @@ def test_parse_network_path(): assert expected == actual -def test_secret_version_path(): +def test_repository_path(): project = "winkle" - secret = "nautilus" - version = "scallop" + location = "nautilus" + connection = "scallop" + repository = "abalone" + expected = "projects/{project}/locations/{location}/connections/{connection}/repositories/{repository}".format( + project=project, + location=location, + connection=connection, + repository=repository, + ) + actual = CloudBuildClient.repository_path(project, location, connection, repository) + assert expected == actual + + +def test_parse_repository_path(): + expected = { + "project": "squid", + "location": "clam", + "connection": "whelk", + "repository": "octopus", + } + path = CloudBuildClient.repository_path(**expected) + + # Check that the path construction is reversible. + actual = CloudBuildClient.parse_repository_path(path) + assert expected == actual + + +def test_secret_version_path(): + project = "oyster" + secret = "nudibranch" + version = "cuttlefish" expected = "projects/{project}/secrets/{secret}/versions/{version}".format( project=project, secret=secret, @@ -13072,9 +13125,9 @@ def test_secret_version_path(): def test_parse_secret_version_path(): expected = { - "project": "abalone", - "secret": "squid", - "version": "clam", + "project": "mussel", + "secret": "winkle", + "version": "nautilus", } path = CloudBuildClient.secret_version_path(**expected) @@ -13084,8 +13137,8 @@ def test_parse_secret_version_path(): def test_service_account_path(): - project = "whelk" - service_account = "octopus" + project = "scallop" + service_account = "abalone" expected = "projects/{project}/serviceAccounts/{service_account}".format( project=project, service_account=service_account, @@ -13096,8 +13149,8 @@ def test_service_account_path(): def test_parse_service_account_path(): expected = { - "project": "oyster", - "service_account": "nudibranch", + "project": "squid", + "service_account": "clam", } path = CloudBuildClient.service_account_path(**expected) @@ -13107,8 +13160,8 @@ def test_parse_service_account_path(): def test_subscription_path(): - project = "cuttlefish" - subscription = "mussel" + project = "whelk" + subscription = "octopus" expected = "projects/{project}/subscriptions/{subscription}".format( project=project, subscription=subscription, @@ -13119,8 +13172,8 @@ def test_subscription_path(): def test_parse_subscription_path(): expected = { - "project": "winkle", - "subscription": "nautilus", + "project": "oyster", + "subscription": "nudibranch", } path = CloudBuildClient.subscription_path(**expected) @@ -13130,8 +13183,8 @@ def test_parse_subscription_path(): def test_topic_path(): - project = "scallop" - topic = "abalone" + project = "cuttlefish" + topic = "mussel" expected = "projects/{project}/topics/{topic}".format( project=project, topic=topic, @@ -13142,8 +13195,8 @@ def test_topic_path(): def test_parse_topic_path(): expected = { - "project": "squid", - "topic": "clam", + "project": "winkle", + "topic": "nautilus", } path = CloudBuildClient.topic_path(**expected) @@ -13153,9 +13206,9 @@ def test_parse_topic_path(): def test_worker_pool_path(): - project = "whelk" - location = "octopus" - worker_pool = "oyster" + project = "scallop" + location = "abalone" + worker_pool = "squid" expected = ( "projects/{project}/locations/{location}/workerPools/{worker_pool}".format( project=project, @@ -13169,9 +13222,9 @@ def test_worker_pool_path(): def test_parse_worker_pool_path(): expected = { - "project": "nudibranch", - "location": "cuttlefish", - "worker_pool": "mussel", + "project": "clam", + "location": "whelk", + "worker_pool": "octopus", } path = CloudBuildClient.worker_pool_path(**expected) @@ -13181,7 +13234,7 @@ def test_parse_worker_pool_path(): def test_common_billing_account_path(): - billing_account = "winkle" + billing_account = "oyster" expected = "billingAccounts/{billing_account}".format( billing_account=billing_account, ) @@ -13191,7 +13244,7 @@ def test_common_billing_account_path(): def test_parse_common_billing_account_path(): expected = { - "billing_account": "nautilus", + "billing_account": "nudibranch", } path = CloudBuildClient.common_billing_account_path(**expected) @@ -13201,7 +13254,7 @@ def test_parse_common_billing_account_path(): def test_common_folder_path(): - folder = "scallop" + folder = "cuttlefish" expected = "folders/{folder}".format( folder=folder, ) @@ -13211,7 +13264,7 @@ def test_common_folder_path(): def test_parse_common_folder_path(): expected = { - "folder": "abalone", + "folder": "mussel", } path = CloudBuildClient.common_folder_path(**expected) @@ -13221,7 +13274,7 @@ def test_parse_common_folder_path(): def test_common_organization_path(): - organization = "squid" + organization = "winkle" expected = "organizations/{organization}".format( organization=organization, ) @@ -13231,7 +13284,7 @@ def test_common_organization_path(): def test_parse_common_organization_path(): expected = { - "organization": "clam", + "organization": "nautilus", } path = CloudBuildClient.common_organization_path(**expected) @@ -13241,7 +13294,7 @@ def test_parse_common_organization_path(): def test_common_project_path(): - project = "whelk" + project = "scallop" expected = "projects/{project}".format( project=project, ) @@ -13251,7 +13304,7 @@ def test_common_project_path(): def test_parse_common_project_path(): expected = { - "project": "octopus", + "project": "abalone", } path = CloudBuildClient.common_project_path(**expected) @@ -13261,8 +13314,8 @@ def test_parse_common_project_path(): def test_common_location_path(): - project = "oyster" - location = "nudibranch" + project = "squid" + location = "clam" expected = "projects/{project}/locations/{location}".format( project=project, location=location, @@ -13273,8 +13326,8 @@ def test_common_location_path(): def test_parse_common_location_path(): expected = { - "project": "cuttlefish", - "location": "mussel", + "project": "whelk", + "location": "octopus", } path = CloudBuildClient.common_location_path(**expected)