
                              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 GitHub 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	)
UpdateGitHub   z*Update GitHub 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UR                  5       nUR                  SSS	9  UR                  5       nUR                  S
SS	9  UR                  SSS	9  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S9  [        R                  " USSS9  [        R                  " U5        [        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--repositoryzkRepository resource (2nd gen) to use, in the format
"projects/*/locations/*/connections/*/repositories/*".
)helpz--repo-ownerzOwner of the GitHub Repository.z--repo-namezName of the GitHub Repository.z--enterprise-configzResource name of the GitHub Enterprise config that should be applied to this
installation.

For example: "projects/{$project_id}/locations/{$location_id}/githubEnterpriseConfigs/{$config_id}
        z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 regex 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-controlzEDo not require comments on Pull Requests before builds are triggered.zjEnforce that repository owners or collaborators must comment on Pull Requests before builds are triggered.zEnforce 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_ONLYr   zkRequire a repository collaborator or owner to comment '/gcbrun' on a pull request before running the build.)choicesdefaultr   )has_build_configrequire_docker_imageN)r
   ConceptParserForResourcer	   GetTriggerResourceSpecAddToParsertrigger_utilsAddTriggerArgsadd_mutually_exclusive_groupadd_argumentadd_argument_groupAddBranchPatternAddTagPatternAddBuildConfigArgsForUpdateAddRepoEventArgsAddIncludeLogsArgs)parserflag_config
gen_config	v1_config
ref_config	pr_configs         ,lib/surface/builds/triggers/update/github.pyArgsUpdateGitHub.Args3   s    !!--,,.	 .  #{6*..7K99;J   --/I>  @<  >   99;J"":.
+--3J-KI 
   A
 #8'  0 --dG"";/$$[1    c           
         [         R                  " 5       n[        R                  " X5      u  pVU(       a  U$ UR	                  UR
                  UR                  UR                  S9nUR                  (       ad  UR                  UR                  S9Ul
        UR                  (       a4  UR                  R                  UR                  5      UR                  l        O)UR                  UR                  UR                   S9Ul        Xul        [        R&                  " UUUUUSSS9  [        R(                  " XQ5        [        R*                  " XQU5        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.
)ownernameenterpriseConfigResourceName)branch)r>   tagNT)r    )r   GetMessagesModuler&   ParseTriggerArgsForUpdateGitHubEventsConfig
repo_owner	repo_nameenterprise_configpull_request_patternPullRequestFilterpullRequestcomment_controlCommentControlValueValuesEnumcommentControl
PushFilterbranch_patterntag_patternpushgithubParseBuildConfigArgsForUpdateParseRepoEventArgsParseIncludeLogsWithStatus)selfargsold_triggerupdate_maskmessagestriggerdoneghs           r6   ParseTriggerFromFlags"UpdateGitHub.ParseTriggerFromFlags   s1    002H!;;DKMGn 
	$	$oo^^%)%;%; 
% 
=B   11** 2 ,bn			&&DD$$ 	% ##$$$*:*: $ bg N// $$W3,,WHENr9   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 GitHub trigger.
Tr   )
projectsIdlocationsId
triggersIdz&cloudbuild.projects.locations.triggers)params
collection)r<   	triggerIdsubstitutionsc                 8   > U R                  T5      (       a  T$ U $ )N)
startswith)msubs    r6   <lambda>"UpdateGitHub.Run.<locals>.<lambda>   s    c!2!2#99r9   ,)resourceNamerd   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-CloudbuildProjectsLocationsTriggersGetRequestr\   extendMessageToFieldPathssortedsetmap/CloudbuildProjectsLocationsTriggersPatchRequestjoinPatchr   UpdatedResource)rT   rU   clientrX   ru   
regionproplocation	triggeridr<   rV   rW   rY   requpdated_triggerri   s                 @r6   RunUpdateGitHub.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r9    N)__name__
__module____qualname____firstlineno____doc__detailed_helpstaticmethodr7   r\   r   __static_attributes__r   r9   r6   r   r      s8    2 -" Q2 Q2f6p6r9   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   r9   r6   <module>r      s?    % &  ' = M ( ? D # * )V4%% Vr9   