
                         2   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  e
j*                  e
j,                  j.                        e
j0                   G d de
j2                                      Zy)z#Create GCB v2 repo trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)concepts)resource_args)concept_parsers)log)
properties)	resourcesc                   4    e Zd ZdZddiZed        Zd Zd Zy)CreateRepositoryz/Create a build trigger for a GCB v2 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" --repository=projects/my-project/locations/my-location/connections/my-connection/repositories/my-repository --branch-pattern=".*" --build-config="cloudbuild.yaml"

            To create a pull request trigger for master:

              $ {command} --name="my-trigger" --service-account="projects/my-project/serviceAccounts/my-byosa@my-project.iam.gserviceaccount.com" --repository=projects/my-project/locations/my-location/connections/my-connection/repositories/my-repository --pull-request-pattern="^master$" --build-config="cloudbuild.yaml"
          c                    t        j                  ddt         j                  t        j                               }t
        j                  j                  d|dd      j                  |        t        j                         }t        j                  | d	      }|j                  d
dd       |j                  d      }t        j                  |       t        j                   |       |j#                  d      }|j                  dddd       |j                  d|j$                  j&                  j(                  d       t        j*                  |d      }t        j,                  |d       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.
    cloudbuild.projects.locationsregion)resource_name
projectsIdlocationsIdz--regionzCloud regionTrequiredF)add_region_flagz--repositoryz'Resource name of the GCB v2 repository.)helpr   zPull Request settings)r   z--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   r   z--comment-controlzkRequire a repository collaborator or owner to comment '/gcbrun' on a pull request before running the build.)defaultr   )add_docker_args)require_docker_imageN)r	   ResourceSpec DEFAULT_PROJECT_ATTRIBUTE_CONFIGr
   RegionAttributeConfigr   ConceptParserForResourceAddToParserr   GetMessagesModuletrigger_utilsAddTriggerArgsadd_argumentadd_mutually_exclusive_groupAddBranchPatternAddTagPatternadd_argument_groupPullRequestFilterCommentControlValueValuesEnumCOMMENTS_ENABLEDAddBuildConfigArgsAddBuildDockerArgsAddRepoEventArgs)parserregion_specmessagesflag_config
ref_config	pr_configbuild_configs          0lib/surface/builds/triggers/create/repository.pyArgszCreateRepository.Args3   si    '''<<!779	;K
 !!--	 .  #{6*002H..vuMKF   9949HJ"":.
+--3J-KI 
	   **HH		|	   	((eL $$\M"";/    c                 @   t        j                         }t        j                  ||      \  }}|r|S |j	                  |j
                        }|j                  rb|j                  |j                        |_        |j                  ra|j                  j                  |j                        |j                  _        n,|j                  |j                  |j                        |_        ||_        t        j"                  |||d       t        j$                  ||       |S )a  Parses command line arguments into a build trigger.

    Args:
      args: An argparse arguments object.

    Returns:
      A build trigger object.

    Raises:
      RequiredArgumentException: If comment_control is defined but
      pull_request_pattern isn't.
    )
repository)branch)rA   tagN)default_image)r   r'   r(   ParseTriggerArgsRepositoryEventConfigr@   pull_request_patternr/   pullRequestcomment_controlr0   commentControl
PushFilterbranch_patterntag_patternpushrepositoryEventConfigParseBuildConfigArgsParseRepoEventArgs)selfargsr7   triggerdonerepos         r<   ParseTriggerFromFlagsz&CreateRepository.ParseTriggerFromFlagsj   s    002H!224BMGTn ))T__)ED  !33** 4 ,d			*2*D*D*b*b  +"' %%$$$*:*: & <di$(G!&&xt5$$Wd3Nr>   c           	         t        j                         }t        j                         }| j                  |      }t        j
                  j                  j                  j                  d      }|j                  }|4t        j
                  j                  j                  j                  d      }|j                  d      d   }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   N/r   )
collectionr   r   )parentbuildTriggerz&cloudbuild.projects.locations.triggersv1)r   r   
triggersId)rZ   api_versionparams)r   GetClientInstancer'   rV   r   VALUEScoreprojectGetr   buildssplitr   REGISTRYCreateRelativeNameprojects_locations_triggers0CloudbuildProjectsLocationsTriggersCreateRequestParseidr   CreatedResource)
rQ   rR   clientr7   rS   rd   locationr[   created_triggertrigger_resources
             r<   RunzCreateRepository.Run   sQ    ..0F002H((.G $$,,00$0?G{{H""))0044d4Ch~~c"2&H&&2 '  +ln  88??AA 	B 	12O !))//;!#),,
	 0  ()r>   N)	__name__
__module____qualname____doc__detailed_helpstaticmethodr=   rV   rt    r>   r<   r   r       s8     8 - 40 40l%N)r>   r   N)rx   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r(   googlecloudsdk.callioper    googlecloudsdk.calliope.conceptsr	   %googlecloudsdk.command_lib.cloudbuildr
   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   r   r   ReleaseTracksReleaseTrackALPHAHiddenCreateCommandr   r{   r>   r<   <module>r      sw    * &  ' = M ( 5 ? D # * ) D%%++,Wt)) W  -Wr>   