
    H                         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
KJr  SSKJr  SSKJr  SSKJr   " S S\
R,                  5      rg)z1Update Cloud Source Repositories trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)resource_args)concept_parsers)presentation_specs)log)
properties)	resourcesc                   <    \ rS rSrSrSS0r\S 5       rS rS r	Sr
g	)
	UpdateCSR!   z>Updates Cloud Source Repositories trigger used by Cloud Build.EXAMPLESa              To update the branch pattern of the trigger:

              $ {command} my-trigger --branch-pattern=".*"

            To update the build config of the trigger:

              $ {command} my-trigger --build-config="cloudbuild.yaml"

            To update the substitutions of the trigger:

              $ {command} my-trigger --update-substitutions=_REPO_NAME=my-repo,_BRANCH_NAME=master
        c                 $   [         R                  R                  S[        R                  " 5       SSS9R                  U 5        [        R                  " U SSS9n[        R                  " S[        R                  " 5       SSS	9n[         R                  " U/5      R                  U5        UR                  5       n[        R                  " U5        [        R                  " U5        [        R                  " USSS
9  [        R                   " U5        g)zRegisters 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.
TRIGGERzBuild Trigger.TrequiredF)add_region_flagadd_namez--repozCloud Source Repository.)prefixes)has_build_configrequire_docker_imageN)r
   ConceptParserForResourcer	   GetTriggerResourceSpecAddToParsertrigger_utilsAddTriggerArgsr   ResourcePresentationSpecrepo_resourceGetRepoResourceSpecadd_mutually_exclusive_groupAddBranchPatternAddTagPatternAddBuildConfigArgsForUpdateAddRepoEventArgs)parserflag_config	repo_spec
ref_configs       ?lib/surface/builds/triggers/update/cloud_source_repositories.pyArgsUpdateCSR.Args5   s     !!--,,.4 . ) *5V)<..7K";;))+"	I
 !!9+.::;G99;J"":.
+--dG"";/    c           
         [         R                  " 5       n[        R                  " X5      u  pVU(       a  U$ UR                  R
                  R                  5       nSnU(       a  UR                  nUR                  UR                  UR                  UR                  UUR                  UR                  S9S9n[        R                  " XQU5        [        R                  " UUUUUSSS9  [        R                   " XQ5        U$ )aG  Parses command line arguments into a build trigger.

Args:
  args: An argparse arguments object.
  old_trigger: The existing trigger to be updated.
  update_mask: The fields to be updated.

Returns:
  A build trigger object.

Raises:
  RequiredArgumentException: If comment_control is defined but
  pull_request_pattern isn't.
N)repoName
branchNametagName)descriptionserviceAccounttriggerTemplate T)r   )r   GetMessagesModuler    ParseTriggerArgsForUpdateCONCEPTSrepoParsereposIdBuildTriggerr6   service_account
RepoSourcebranch_patterntag_patternParseRequireApprovalParseBuildConfigArgsForUpdateParseRepoEventArgs)	selfargsold_triggerupdate_maskmessagestriggerdonerepo_refr=   s	            r.   ParseTriggerFromFlagsUpdateCSR.ParseTriggerFromFlagsR   s     002H!;;DKMGn}}!!'')HDd##$$++ ++**$$ , 
 $ G &&wh? //
 $$W3Nr1   c                   ^ [         R                  " 5       n[         R                  " 5       n[        R                  R
                  R                  R                  SS9n[        R                  R                  R                  R                  5       nUR                  =(       d    U=(       d    [         R                  nUR                  n[        R                  R                  UUUUS.SS9R                  5       nUR                   R                  UR"                  R%                  XS95      n	/ n
U R'                  XU
5      nSmU
R)                  [         R*                  " U5      5        [-        [/        [1        U4S jU
5      5      5      n
UR3                  UUUS	R5                  U
5      S
9nUR                   R7                  U5      n[8        R:                  " USS9  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 updated CSR trigger.
Tr   )
projectsIdlocationsId
triggersIdz&cloudbuild.projects.locations.triggers)params
collection)name	triggerIdsubstitutionsc                 8   > U R                  T5      (       a  T$ U $ )N)
startswith)msubs    r.   <lambda>UpdateCSR.Run.<locals>.<lambda>   s    c!2!2#99r1   ,)resourceNamerY   buildTrigger
updateMaskbuild_trigger)kind)r   GetClientInstancer:   r   VALUEScoreprojectGetbuildsregionDEFAULT_REGIONr   r   REGISTRYr>   RelativeNameprojects_locations_triggersMESSAGES_MODULE-CloudbuildProjectsLocationsTriggersGetRequestrP   extendMessageToFieldPathslistsetmap/CloudbuildProjectsLocationsTriggersPatchRequestjoinPatchr   UpdatedResource)rH   rI   clientrL   rj   
regionproplocation	triggeridrX   rJ   rK   rM   requpdated_triggerr^   s                 @r.   RunUpdateCSR.Run   s    ..0F002H$$,,00$0?G""))00446J{{JjJO,J,JHI##!##

 < $ = >J\^ 	 4488LL 	M 	,-K K((KHG C::7CDC9;GHJK 
B
B88K(	 C *C 88>>sCO	8r1    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr/   rP   r   __static_attributes__r   r1   r.   r   r   !   s5    F -" 0 080d1r1   r   N)r   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r    googlecloudsdk.callioper   %googlecloudsdk.command_lib.cloudbuildr	   !googlecloudsdk.command_lib.sourcer#   (googlecloudsdk.command_lib.util.conceptsr
   r   googlecloudsdk.corer   r   r   UpdateCommandr   r   r1   r.   <module>r      sE    8 &  ' = M ( ? L D G # * )T"" Tr1   