
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ  G d de
j                        Zd Zy)zCreate Pub/Sub trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)log)
properties)	resourcesc                   .    e Zd ZdZddiZed        Zd Zy)CreatePubSubz4Create a build trigger with a Pub/Sub trigger event.EXAMPLESaJ              To create a Pub/Sub trigger that listens to topic `my-topic` and builds off branch `my-branch` in a GitHub repository named `my-repo`:

              $ {command} --name=my-pubsub-trigger --service-account="projects/my-project/serviceAccounts/my-byosa@my-project.iam.gserviceaccount.com" --topic=projects/my-project/topics/my-topic --repo=https://www.github.com/owner/repo --repo-type=GITHUB --branch=my-branch

            To create a Pub/Sub trigger that listens to topic `my-topic` and builds off branch `my-branch` in a 2nd-gen GitHub repository resource:

              $ {command} --name=my-pubsub-trigger --service-account="projects/my-project/serviceAccounts/my-byosa@my-project.iam.gserviceaccount.com" --repository=projects/my-proj/locations/us-west1/connections/my-conn/repositories/my-repo --branch=my-branch
          c                     t        j                  |       }|j                  ddd       t        j                  |       t        j                  |       t        j
                  |       y)zfRegister flags for this command.

    Args:
      parser: An argparse.ArgumentParser-like object.
    z--topicz1The topic to which this trigger should subscribe.T)helprequiredN)trigger_utilsAddTriggerArgsadd_argumentAddBuildConfigArgsAddGitRepoSourceAddFilterArg)parserflag_configs     ,lib/surface/builds/triggers/create/pubsub.pyArgszCreatePubSub.Args-   s\      ..v6K@   $$[1"";/{+    c           	      V   t        j                         }t        j                         }|j                         }|j                  r/t        j
                  |j                  |j                  ddg      }nt        |      }t        j                  j                  j                  j                  d      }t        j                  j                  j                  j                         }|j                  xs |xs t         j                  }t        j                   j#                  d||      j%                         }|j&                  j#                  |j)                  ||            }	t        j                   j+                  d	d
d|||	j,                  d      }
t/        j0                  |
       |	S )zThis is what gets called when the user runs this command.

    Args:
      args: An argparse namespace. All the arguments that were provided to this
        command invocation.

    Returns:
      The newly created trigger.
    zbuild trigger configsubstitutions)pathmsg_typemsg_friendly_nameskip_camel_caseTr   zcloudbuild.projects.locations)
collection
projectsIdlocationsId)parentbuildTriggerNz&cloudbuild.projects.locations.triggersv1)r%   r&   
triggersId)r$   api_versionparams)r   GetClientInstanceGetMessagesModuleBuildTriggerr   LoadMessageFromPathParseTriggerFromFlagsr
   VALUEScoreprojectGetbuildsregionDEFAULT_REGIONr   REGISTRYCreateRelativeNameprojects_locations_triggers0CloudbuildProjectsLocationsTriggersCreateRequestParseidr	   CreatedResource)selfargsclientmessagestriggerr4   
regionproplocationr'   created_triggertrigger_resources              r   RunzCreatePubSub.Run>   s    ..0F002H##%G33""((2*+	-g &d+g $$,,00$0?G""))00446J{{JjJO,J,JH&&2 '  +ln  88??AA 	B 	12O !))//;!#),,
	 0  ()r   N)__name__
__module____qualname____doc__detailed_helpstaticmethodr   rJ    r   r   r   r      s/    < - , , /r   r   c                    t        j                         }t        j                  | |      \  }}|r|S | j                  |_        |j                  | j                        |_        t        j                  j                  j                  j                  d      }d|d| j                  d}t        j                  || ||d       | j                  |_        |S )zParse arguments into a BuildTrigger proto.

  Args:
    args: An argparse.Namespace. All the arguments that were provided to this
      command invocation.

  Returns:
    A BuildTrigger proto object.
  )topicTr#   zgcr.io/z/gcb-z:$COMMIT_SHA)	need_repo)r   r.   r   ParseTriggerArgsnamePubsubConfigrS   pubsubConfigr
   r2   r3   r4   r5   ParseBuildConfigArgssubscription_filterfilter)rB   rD   rE   doner4   default_images         r   r1   r1   p   s     ..0(00x@-'4	N',!..TZZ.@' ""**...='4;TYYG-$$tX}> ++'.	.r   N)rN   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r   CreateCommandr   r1   rQ   r   r   <module>rc      s?    & &  ' = M ( # * )P4%% Pfr   