
    "                         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\
R&                  5      rg)z-Update Bitbucket Data Center trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)resource_args)concept_parsers)log)
properties)	resourcesc                   <    \ rS rSrSrSS0r\S 5       rS rS r	Sr
g	)
UpdateBitbucketDataCenter   z:Updates Bitbucket Data Center trigger used by Cloud Build.EXAMPLESac              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

            To update the 2nd-gen repository resource of the trigger:

              $ {command} my-trigger --repository=projects/my-project/locations/us-west1/connections/my-conn/repositories/my-repo
        c                    [         R                  R                  S[        R                  " 5       SSS9R                  U 5        [        R                  " U SSS9nUR                  SSS	9  UR                  5       n[        R                  " U5        [        R                  " U5        UR                  S
S	9nUR                  SSSS9  UR                  SSSSS.SS9  [        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--repositoryzjRepository resource (2nd gen) to use, in the format "projects/*/locations/*/connections/*/repositories/*".)helpzPull Request settingsz--pull-request-patternREGEXa  A regular expression specifying which base git branch to match for
pull request events.

This pattern is used as a regular expression search for the base branch (the
branch you are trying to merge into) for pull request updates.
For example, --pull-request-pattern=foo will match "foo", "foobar", and "barfoo".

The syntax of the regular expressions accepted is the syntax accepted by
RE2 and described at https://github.com/google/re2/wiki/Syntax.
)metavarr   z--comment-controlzF
Do not require comments on Pull Requests before builds are triggered.zk
Enforce that repository owners or collaborators must comment on Pull Requests
before builds are triggered.z
Enforce that repository owners or collaborators must comment on external
contributors' Pull Requests before builds are triggered.)COMMENTS_DISABLEDCOMMENTS_ENABLED/COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLYzlRequire a repository collaborator or owner to comment '/gcbrun' on a pull
request before running the build.
)choicesr   )has_build_configrequire_docker_imageN)r
   ConceptParserForResourcer	   GetTriggerResourceSpecAddToParsertrigger_utilsAddTriggerArgsadd_argumentadd_mutually_exclusive_groupAddBranchPatternAddTagPatternadd_argument_groupAddBuildConfigArgsForUpdateAddRepoEventArgs)parserflag_config
ref_config	pr_configs       ;lib/surface/builds/triggers/update/bitbucket_data_center.pyArgsUpdateBitbucketDataCenter.Args6   s+    !!--,,.	 . 
 k&..K F   99;J"":.
+--3J-KI 
   "I! @<	
  $ --d "";/    c           
      .   [         R                  " 5       n[        R                  " X5      u  pVU(       a  U$ UR                  (       a  UR                  UR                  S9nXul        UR                  (       a[  UR                  c  UR                  5       Ul        UR                  UR                  S9UR                  l	        UR                  S5        UR                  (       a[  UR                  c  UR                  5       Ul        UR                  UR                  S9UR                  l	        UR                  S5        UR                  (       a]  UR                  nUR                  c  UR                  5       Ul        UR                  US9UR                  l        UR                  S5        UR                  (       a  UR                  c  UR                  5       Ul        UR                  R                  c  UR                  5       UR                  l        UR                  R!                  UR                  5      UR                  R                  l        UR                  S5        [        R$                  " UUUUUSSS9  [        R&                  " XQ5        U$ )	a>  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 update mask.

Returns:
  A build trigger object.

Raises:
  RequiredArgumentException: If comment_control is defined but
  pull_request_pattern isn't.
)
repositoryN)branchz$repository_event_config.pull_request)tagzrepository_event_config.pushT)r   )r   GetMessagesModuler%   ParseTriggerArgsForUpdater7   RepositoryEventConfigrepositoryEventConfigbranch_pattern
PushFilterpushappendtag_patternpull_request_patternPullRequestFilterpullRequestcomment_controlCommentControlValueValuesEnumcommentControlParseBuildConfigArgsForUpdateParseRepoEventArgs)	selfargsold_triggerupdate_maskmessagestriggerdonereporC   s	            r2   ParseTriggerFromFlags/UpdateBitbucketDataCenter.ParseTriggerFromFlagsy   s<    002H!;;DKMGn++t+Gd&*# 		&	&	.(0(F(F(H%+3+>+>$$ ,? ,g##( ?@		&	&	.(0(F(F(H%+3+>+> ,? ,g##( ?@  !66		&	&	.(0(F(F(H%2:2L2L% 3M 3g##/ 78		&	&	.(0(F(F(H%		&	&	2	2	:4<4N4N4P%%1

$
$
B
B"" ##//>
 78// $$W3Nr5   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                  5         UR5                  UUUS	R7                  U
5      S
9nUR                   R9                  U5      n[:        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 Bitbucket Data Center 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    r2   <lambda>/UpdateBitbucketDataCenter.Run.<locals>.<lambda>   s    c!2!2#99r5   ,)resourceNamer\   buildTrigger
updateMaskbuild_trigger)kind)r   GetClientInstancer:   r   VALUEScoreprojectGetbuildsregionDEFAULT_REGIONr   r   REGISTRYParseRelativeNameprojects_locations_triggersMESSAGES_MODULE-CloudbuildProjectsLocationsTriggersGetRequestrS   extendMessageToFieldPathslistsetmapsort/CloudbuildProjectsLocationsTriggersPatchRequestjoinPatchr   UpdatedResource)rK   rL   clientrO   rm   
regionproplocation	triggeridr[   rM   rN   rP   requpdated_triggerra   s                 @r2   RunUpdateBitbucketDataCenter.Run   s    ..0F002H$$,,00$0?G""))00446J{{JjJO,J,JHI##!##

 < $  ln 	 4488LL 	M 	
K K((KHG C::7CDC9;GHK 

B
B88K(	 C C 88>>sCO	8r5    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr3   rS   r   __static_attributes__r   r5   r2   r   r      s9    B  -( @0 @0DJX8r5   r   N)r   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r%   googlecloudsdk.callioper   %googlecloudsdk.command_lib.cloudbuildr	   (googlecloudsdk.command_lib.util.conceptsr
   googlecloudsdk.corer   r   r   UpdateCommandr   r   r5   r2   <module>r      s?    4 &  ' = M ( ? D # * )^ 2 2 ^r5   