
                             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 ddlmZ ddlmZ ddlmZ  G d de
j*                        Zy)z1Create Cloud Source Repositories trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)resource_args)concept_parsers)presentation_specs)log)
properties)	resourcesc                   4    e Zd ZdZddiZed        Zd Zd Zy)	CreateCSRz6Create a build trigger from a Cloud Source Repository.EXAMPLESa              To create a push trigger for all branches:

              $ {command} --name="my-trigger" --service-account="projects/my-project/serviceAccounts/my-byosa@my-project.iam.gserviceaccount.com" --repo="my-repo" --branch-pattern=".*" --build-config="cloudbuild.yaml"
          c                    t        j                  |       }t        j                  dt	        j
                         ddd      }t        j                  |g      j                  |       |j                  d      }t        j                  |       t        j                  |       t        j                  |       t        j                  |       y)zRegister flags for this command.

    Args:
      parser: An argparse.ArgumentParser-like object. It is mocked out in order
        to capture some information, but behaves like an ArgumentParser.
    z--repozCloud Source Repository.TF)requiredprefixesr   N)trigger_utilsAddTriggerArgsr   ResourcePresentationSpecrepo_resourceGetRepoResourceSpecr
   ConceptParserAddToParseradd_mutually_exclusive_groupAddBranchPatternAddTagPatternAddBuildConfigArgsAddRepoEventArgs)parserflag_config	repo_spec
ref_configs       ?lib/surface/builds/triggers/create/cloud_source_repositories.pyArgszCreateCSR.Args,   s      ..v6K";;))+"I !!9+.::;G9949HJ"":.
+$$[1"";/    c           
      ~   t        j                         }t        j                  ||      \  }}|r|S |j                  j
                  j                         }|j                  }|j                  |j                  |j                  |j                  |j                  ||j                  |j                              }t        j                  |||       t         j"                  j$                  j&                  j)                  d      }d|d|d}t        j*                  ||||       t        j,                  ||       |S )zParses command line arguments into a build trigger.

    Args:
      args: An argparse arguments object.

    Returns:
      A build trigger object.
    )repoName
branchNametagName)namedescriptionserviceAccounttriggerTemplateTr   zgcr.io//z:$COMMIT_SHA)r   GetMessagesModuler   ParseTriggerArgsCONCEPTSrepoParsereposIdBuildTriggerr-   r.   service_account
RepoSourcebranch_patterntag_patternParseRequireApprovalr   VALUEScoreprojectGetParseBuildConfigArgsParseRepoEventArgs)	selfargsmessagestriggerdonerepo_refr5   r@   default_images	            r&   ParseTriggerFromFlagszCreateCSR.ParseTriggerFromFlagsD   s    002H!224BMGTn}}!!'')HD##YY$$++ ++**$$ , 
	 $ 	G &&wh? $$,,00$0?G294@M&&whN$$Wd3Nr(   c           	         t        j                         }| j                  |      }t        j                         }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)        j*                  |
       |	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:
      Some value that we want to have printed later.
    Tr   zcloudbuild.projects.locations)
collection
projectsIdlocationsId)parentbuildTriggerNz&cloudbuild.projects.locations.triggersv1)rN   rO   
triggersId)rM   api_versionparams)r   r2   rK   GetClientInstancer   r>   r?   r@   rA   buildsregionDEFAULT_REGIONr   REGISTRYCreateRelativeNameprojects_locations_triggers0CloudbuildProjectsLocationsTriggersCreateRequestr6   idr   CreatedResource)rD   rE   rF   rG   clientr@   
regionproplocationrP   created_triggertrigger_resources              r&   RunzCreateCSR.Runi   sC    002H((.G ..0F$$,,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'   rK   rf    r(   r&   r   r       s5    > - 0 0.#J&r(   r   N)rj   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.callioper   !googlecloudsdk.command_lib.sourcer	   r   (googlecloudsdk.command_lib.util.conceptsr
   r   googlecloudsdk.corer   r   r   CreateCommandr   rm   r(   r&   <module>ru      sB    8 &  ' = M ( L D G # * )o"" or(   