
    ~                         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  G d de
j                        Zd Zy)zCreate manual trigger command.    )absolute_import)division)unicode_literals)cloudbuild_util)trigger_config)base)log)
properties)	resourcesc                   .    e Zd ZdZddiZed        Zd Zy)CreateManualz3Create a build trigger with a manual trigger event.EXAMPLESaR              To create a manual trigger that builds off branch `my-branch` in a GitHub repository named `my-repo`:

              $ {command} --name=my-manual-trigger --build-config=cloudbuild.yaml --repo=https://www.github.com/owner/repo --repo-type=GITHUB --branch=my-branch

            To create a manual trigger that builds off branch `my-branch` in a 2nd-gen GitHub repository resource:

              $ {command} --name=my-manual-trigger --build-config=cloudbuild.yaml --repository=projects/my-proj/locations/us-west1/connections/my-conn/repositories/my-repo --branch=my-branch
          c                     t        j                  |       }t        j                  |       t        j                  |       y)zfRegister flags for this command.

    Args:
      parser: An argparse.ArgumentParser-like object.
    N)trigger_utilsAddTriggerArgsAddBuildConfigArgsAddGitRepoSource)parserflag_configs     ,lib/surface/builds/triggers/create/manual.pyArgszCreateManual.Args-   s0      ..v6K$$[1"";/    c           	      V   t        j                         }t        j                         }|j                         }|j                  r/t        j
                  |j                  |j                  ddg      }nt        |      }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/        j0                  |
       |	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:
      The newly created trigger.
    zbuild trigger configsubstitutions)pathmsg_typemsg_friendly_nameskip_camel_caseTrequiredzcloudbuild.projects.locations)
collection
projectsIdlocationsId)parentbuildTriggerNz&cloudbuild.projects.locations.triggersv1)r"   r#   
triggersId)r!   api_versionparams)r   GetClientInstanceGetMessagesModuleBuildTriggerr   LoadMessageFromPathParseTriggerFromFlagsr
   VALUEScoreprojectGetbuildsregionDEFAULT_REGIONr   REGISTRYCreateRelativeNameprojects_locations_triggers0CloudbuildProjectsLocationsTriggersCreateRequestParseidr	   CreatedResource)selfargsclientmessagestriggerr1   
regionproplocationr$   created_triggertrigger_resources              r   RunzCreateManual.Run9   s    ..0F002H##%G33""((2*+	-g &d+g $$,,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   rG    r   r   r   r      s/    ; - 	0 	0/r   r   c                 L   t        j                         }t        j                  | |      \  }}|r|S | j                  |_        t
        j                  j                  j                  j                  d      }d|d| j                  d}t        j                  || ||d       |S )zParse arguments into a BuildTrigger proto.

  Args:
    args: An argparse.Namespace. All the arguments that were provided to this
      command invocation.

  Returns:
    A BuildTrigger proto object.
  Tr   zgcr.io/z/gcb-z:$COMMIT_SHA)	need_repo)r   r+   r   ParseTriggerArgsnamer
   r/   r0   r1   r2   ParseBuildConfigArgs)r?   rA   rB   doner1   default_images         r   r.   r.   k   s     ..0(00x@-'4	N', ""**...='4;TYYG-$$tX}> 
.r   N)rK   
__future__r   r   r   !googlecloudsdk.api_lib.cloudbuildr   r   r   googlecloudsdk.callioper   googlecloudsdk.corer	   r
   r   CreateCommandr   r.   rN   r   r   <module>r[      s?    % &  ' = M ( # * )K4%% K\r   