
                             S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SS	KJr  SS
KJr   " S S\
R                  5      rS rg)zCreate Pub/Sub trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)log)
properties)	resourcesc                   6    \ rS rSrSrSS0r\S 5       rS rSr	g)	CreatePubSub   z4Create 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                     [         R                  " U 5      nUR                  SSSS9  [         R                  " U5        [         R                  " U5        [         R
                  " U5        g)zZRegister 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ArgsCreatePubSub.Args-   s\      ..v6K@   $$[1"";/{+    c           	      \   [         R                  " 5       n[         R                  " 5       nUR                  5       nUR                  (       a-  [         R
                  " UR                  UR                  SS/S9nO[        U5      n[        R                  R                  R                  R                  SS9n[        R                  R                  R                  R                  5       nUR                  =(       d    U=(       d    [         R                  n[        R                   R#                  SUUS9R%                  5       nUR&                  R#                  UR)                  XS95      n	[        R                   R+                  S	S
SUUU	R,                  S.S9n
[.        R0                  " U
5        U	$ )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triggerr6   
regionproplocationr)   created_triggertrigger_resources              r   Run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____firstlineno____doc__detailed_helpstaticmethodr   rL   __static_attributes__rN   r   r   r   r      s/    < - , , /r   r   c                    [         R                  " 5       n[        R                  " X5      u  p#U(       a  U$ U R                  Ul        UR                  U R                  S9Ul        [        R                  R                  R                  R                  SS9nSU< SU R                  < S3n[        R                  " X XSS9  U R                  Ul        U$ )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   r0   r   ParseTriggerArgsnamePubsubConfigrX   pubsubConfigr
   r4   r5   r6   r7   ParseBuildConfigArgssubscription_filterfilter)rD   rF   rG   doner6   default_images         r   r3   r3   p   s     ..0(00@-'	N',!..TZZ.@' ""**...='4;TYYG-$$X> ++'.	.r   N)rS   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r   CreateCommandr   r3   rN   r   r   <module>rh      s?    & &  ' = M ( # * )P4%% Pfr   