def ParseTriggerFromFlags(args):
    """Parse 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.
  """
    messages = cloudbuild_util.GetMessagesModule()

    trigger, done = trigger_utils.ParseTriggerArgs(args, messages)
    if done:
        return trigger

    trigger.name = args.name
    trigger.pubsubConfig = messages.PubsubConfig(topic=args.topic)

    # Build Config
    project = properties.VALUES.core.project.Get(required=True)
    default_image = 'gcr.io/%s/gcb-%s:$COMMIT_SHA' % (project, args.name)
    trigger_utils.ParseBuildConfigArgs(trigger,
                                       args,
                                       messages,
                                       default_image,
                                       need_repo=True)

    trigger.filter = args.filter

    return trigger
Exemplo n.º 2
0
  def ParseTriggerFromFlags(self, args):
    """Parses command line arguments into a build trigger.

    Args:
      args: An argparse arguments object.

    Returns:
      A build trigger object.
    """
    messages = cloudbuild_util.GetMessagesModule()

    trigger, done = trigger_utils.ParseTriggerArgs(args, messages)
    if done:
      return trigger

    repo_ref = args.CONCEPTS.repo.Parse()
    repo = repo_ref.reposId
    trigger = messages.BuildTrigger(
        name=args.name,
        description=args.description,
        triggerTemplate=messages.RepoSource(
            repoName=repo,
            branchName=args.branch_pattern,
            tagName=args.tag_pattern,
        ),
    )

    # Build Config
    project = properties.VALUES.core.project.Get(required=True)
    default_image = 'gcr.io/%s/%s:$COMMIT_SHA' % (project, repo)
    trigger_utils.ParseBuildConfigArgs(trigger, args, messages, default_image)
    trigger_utils.ParseRepoEventArgs(trigger, args)

    return trigger
Exemplo n.º 3
0
    def ParseTriggerFromFlags(self, args):
        """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.
    """
        project = properties.VALUES.core.project.Get(required=True)
        messages = cloudbuild_util.GetMessagesModule()

        trigger, done = trigger_utils.ParseTriggerArgs(args, messages)
        if done:
            return trigger

        # Bitbucket Server config
        bbs = messages.BitbucketServerTriggerConfig(
            repoSlug=args.repo_slug,
            projectKey=args.project_key,
            bitbucketServerConfigResource=args.bitbucket_server_config_resource
        )
        if args.pull_request_pattern:
            bbs.pullRequest = messages.PullRequestFilter(
                branch=args.pull_request_pattern)
            if args.comment_control:
                bbs.pullRequest.commentControl = messages.PullRequestFilter.CommentControlValueValuesEnum(
                    args.comment_control)
        else:
            # Push event
            bbs.push = messages.PushFilter(branch=args.branch_pattern,
                                           tag=args.tag_pattern)
        trigger.bitbucketServerTriggerConfig = bbs

        default_image = 'gcr.io/%s/bitbucketserver-%s/%s:$COMMIT_SHA' % (
            project, args.project_key, args.repo_slug)
        trigger_utils.ParseBuildConfigArgs(trigger, args, messages,
                                           default_image)
        trigger_utils.ParseRepoEventArgs(trigger, args)

        return trigger
    def ParseTriggerFromFlags(self, args):
        """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.
    """
        project = properties.VALUES.core.project.Get(required=True)
        messages = cloudbuild_util.GetMessagesModule()

        trigger, done = trigger_utils.ParseTriggerArgs(args, messages)
        if done:
            return trigger

        # GitHub config
        gh = messages.GitHubEventsConfig(owner=args.repo_owner,
                                         name=args.repo_name)
        if args.pull_request_pattern:
            gh.pullRequest = messages.PullRequestFilter(
                branch=args.pull_request_pattern)
            if args.comment_control:
                gh.pullRequest.commentControl = messages.PullRequestFilter.CommentControlValueValuesEnum(
                    args.comment_control)
        else:
            # Push event
            gh.push = messages.PushFilter(branch=args.branch_pattern,
                                          tag=args.tag_pattern)
        trigger.github = gh

        default_image = 'gcr.io/%s/github.com/%s/%s:$COMMIT_SHA' % (
            project, args.repo_owner, args.repo_name)
        trigger_utils.ParseBuildConfigArgs(trigger, args, messages,
                                           default_image)
        trigger_utils.ParseRepoEventArgs(trigger, args)
        trigger_utils.ParseIncludeLogsWithStatus(trigger, args, messages)

        return trigger
Exemplo n.º 5
0
    def ParseTriggerFromFlags(self, args):
        """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.
    """
        project = properties.VALUES.core.project.Get(required=True)
        messages = cloudbuild_util.GetMessagesModule()

        trigger, done = trigger_utils.ParseTriggerArgs(args, messages)
        if done:
            return trigger

        # GitLab Enterprise config
        gl = messages.GitLabEventsConfig(
            projectNamespace=args.project_namespace,
            gitlabConfigResource=args.gitlab_config_resource)
        if args.pull_request_pattern:
            gl.pullRequest = messages.PullRequestFilter(
                branch=args.pull_request_pattern)
            if args.comment_control:
                gl.pullRequest.commentControl = messages.PullRequestFilter.CommentControlValueValuesEnum(
                    args.comment_control)
        else:
            # Push event
            gl.push = messages.PushFilter(branch=args.branch_pattern,
                                          tag=args.tag_pattern)
        trigger.gitlabEnterpriseEventsConfig = gl

        default_image = 'gcr.io/%s/gitlab-%s:$COMMIT_SHA' % (
            project, args.project_namespace)
        trigger_utils.ParseBuildConfigArgs(trigger, args, messages,
                                           default_image)
        trigger_utils.ParseRepoEventArgs(trigger, args)

        return trigger