Example #1
0
    def Run(self, args):
        """Create a GCP repository to the current directory.

    Args:
      args: argparse.Namespace, the arguments this command is run with.

    Returns:
      The path to the new git repository.

    Raises:
      ToolException: on project initialization errors.
      RepoCreationError: on repo creation errors.
    """

        project_id = properties.VALUES.core.project.Get(required=True)
        project = source.Project(project_id)
        try:
            path = project.CreateRepo(args.name)
            log.CreatedResource(path)
            return path
        except exceptions.HttpError as e:
            message = ('Failed to create repository [{name}] for Project '
                       '[{prj}] with error [{err}].\n'.format(prj=project_id,
                                                              name=args.name,
                                                              err=e))
            raise source.RepoCreationError(message)
Example #2
0
    def GetCaptureRepo(self, create_if_missing=True):
        """Returns the repo where captures will be created.

    Args:
      create_if_missing: (Boolean) Indicates that the repo should be created if
          it does not exist.
    Returns:
      (Repo) The capture repository.
    """

        if self._repo or not create_if_missing:
            return self._repo

        # Verify that the capture repo exists, and if not, create it.
        project = source.Project(self._project_id)
        if not project.GetRepo(self._repo_name):
            project.CreateRepo(self._repo_name)
        self._repo = source.Repo(self._project_id, self._repo_name)
        return self._repo
Example #3
0
    def _PickRepo(self, project_id):
        """Allows user to clone one of the projects repositories."""
        answer = console_io.PromptContinue(
            prompt_string='Do you want to use Google\'s source hosting (see '
            '"https://cloud.google.com/source-repositories/docs/")')
        if not answer:
            return

        try:
            source.Source.SetApiEndpoint(self.Http())
            project = source.Project(project_id)
            repos = project.ListRepos()
        except Exception:  # pylint: disable=broad-except
            # This command is experimental right now; its failures shouldn't affect
            # operation.
            repos = None

        if repos:
            repos = sorted(repo.name or 'default' for repo in repos)
            log.status.write(
                'This project has one or more associated Git repositories.\n')
            idx = console_io.PromptChoice(
                ['[{0}]'.format(repo) for repo in repos] + ['Do not clone'],
                message='Pick Git repository to clone to your local machine:',
                prompt_string=None)
            if idx >= 0 and idx < len(repos):
                repo_name = repos[idx]
            else:
                return
        elif repos is None:
            answer = console_io.PromptContinue(
                prompt_string='Generally projects have a Git repository named '
                '[default]. Would you like to try clone it')
            if not answer:
                return
            repo_name = 'default'
        else:
            return

        self._CloneRepo(repo_name)
Example #4
0
 def Run(self, args):
   """Run the list command."""
   project = source.Project(properties.VALUES.core.project.Get(required=True))
   return project.ListRepos()