How to use the tsrc.cli function in tsrc

To help you get started, we’ve selected a few tsrc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TankerHQ / tsrc / tsrc / cli / push_github.py View on Github external
import argparse
import sys
from typing import Optional

import github3
from github3 import GitHub
from github3.pulls import PullRequest
import cli_ui as ui

import tsrc
import tsrc.github
from tsrc.cli.push import RepositoryInfo


class PushAction(tsrc.cli.push.PushAction):
    def __init__(
        self,
        repository_info: RepositoryInfo,
        args: argparse.Namespace,
        github_api: Optional[GitHub] = None,
    ) -> None:
        super().__init__(repository_info, args)
        self.github_api = github_api
        self.repository = None
        self.pull_request = None

    def setup_service(self) -> None:
        if not self.github_api:
            self.github_api = tsrc.github.login()
        assert self.project_name
        owner, name = self.project_name.split("/")
github TankerHQ / tsrc / tsrc / cli / push.py View on Github external
def main(args: argparse.Namespace) -> None:
    workspace = tsrc.cli.get_workspace(args)

    repository_info = RepositoryInfo.read(Path.getcwd(), workspace=workspace)
    service_name = repository_info.service
    module = importlib.import_module("tsrc.cli.push_%s" % service_name)
    push_action = module.PushAction(repository_info, args)  # type: ignore
    push_action.execute()
github TankerHQ / tsrc / tsrc / cli / log.py View on Github external
def main(args: argparse.Namespace) -> None:
    workspace = tsrc.cli.get_workspace(args)
    all_ok = True
    for unused_index, repo, full_path in workspace.enumerate_repos():
        colors = ["green", "reset", "yellow", "reset", "bold blue", "reset"]
        log_format = "%m {}%h{} - {}%d{} %s {}<%an>{}"
        log_format = log_format.format(*("%C({})".format(x) for x in colors))
        cmd = [
            "log",
            "--color=always",
            "--pretty=format:%s" % log_format,
            "%s...%s" % (args.from_, args.to),
        ]
        rc, out = tsrc.git.run_captured(full_path, *cmd, check=False)
        if rc != 0:
            all_ok = False
        if out:
            ui.info(ui.bold, repo.src)
github TankerHQ / tsrc / tsrc / cli / foreach.py View on Github external
def main(args: argparse.Namespace) -> None:
    workspace = tsrc.cli.get_workspace(args)
    workspace.load_manifest()
    cmd_runner = CmdRunner(
        workspace.root_path, args.cmd, args.cmd_as_str, shell=args.shell
    )
    manifest = workspace.local_manifest.manifest
    assert manifest
    cloned_repos = workspace.get_repos()
    requested_repos = manifest.get_repos(groups=args.groups)

    found = [x for x in requested_repos if x in cloned_repos]
    missing = [x for x in requested_repos if x not in cloned_repos]

    tsrc.run_sequence(found, cmd_runner)
    if missing:
        ui.warning("The following repos were skipped:")
        for repo in missing:
github TankerHQ / tsrc / tsrc / cli / status.py View on Github external
def main(args: argparse.Namespace) -> None:
    workspace = tsrc.cli.get_workspace(args)
    status_collector = StatusCollector(workspace.root_path)
    tsrc.run_sequence(workspace.get_repos(), status_collector)
github TankerHQ / tsrc / tsrc / cli / sync.py View on Github external
def main(args: argparse.Namespace) -> None:
    workspace = tsrc.cli.get_workspace(args)
    ui.info_2("Updating manifest")
    workspace.update_manifest()

    config = workspace.config
    groups = config.repo_groups
    all_repos = config.clone_all_repos
    if groups and not all_repos:
        ui.info(ui.green, "*", ui.reset, "Using groups from config:", ", ".join(groups))
    if all_repos:
        ui.info(ui.green, "*", ui.reset, "Synchronizing all repos")

    workspace.clone_missing()
    workspace.set_remotes()
    workspace.sync(force=args.force)
    workspace.copy_files()
    ui.info("Done", ui.check)
github TankerHQ / tsrc / tsrc / cli / push_git.py View on Github external
""" Ability to push to a standard Git system without requiring Github or Gitlab.
    No pull requests will be automatically created. """

import argparse
import tsrc.git
from tsrc.cli.push import RepositoryInfo


class PushAction(tsrc.cli.push.PushAction):
    def __init__(
        self, repository_info: RepositoryInfo, args: argparse.Namespace
    ) -> None:
        super().__init__(repository_info, args)

    def setup_service(self) -> None:
        pass

    def post_push(self) -> None:
        pass
github TankerHQ / tsrc / tsrc / cli / push_gitlab.py View on Github external
def wipify(title: str) -> str:
    if not title.startswith(WIP_PREFIX):
        return WIP_PREFIX + title
    else:
        return title


def unwipify(title: str) -> str:
    if title.startswith(WIP_PREFIX):
        return title[len(WIP_PREFIX) :]
    else:
        return title


class PushAction(tsrc.cli.push.PushAction):
    def __init__(
        self,
        repository_info: RepositoryInfo,
        args: argparse.Namespace,
        gitlab_api: Optional[Gitlab] = None,
    ) -> None:
        super().__init__(repository_info, args)
        self.gitlab_api = gitlab_api
        self.group = None  # type: Optional[Group]
        self.project = None  # type: Optional[Project]
        self.review_candidates = []  # type: List[User]

    def _get_group(self, group_name: str) -> Optional[Group]:
        assert self.gitlab_api
        try:
            return self.gitlab_api.groups.get(group_name)
github TankerHQ / tsrc / tsrc / cli / push_github_enterprise.py View on Github external
import tsrc.cli.push_github
import argparse
from typing import Optional

from github3 import GitHub

import tsrc
import tsrc.github
from tsrc.cli.push import RepositoryInfo


class PushAction(tsrc.cli.push_github.PushAction):
    def __init__(
        self,
        repository_info: RepositoryInfo,
        args: argparse.Namespace,
        github_api: Optional[GitHub] = None,
    ) -> None:
        if not github_api:
            github_api = tsrc.github.login(
                github_enterprise_url=repository_info.repository_login_url
            )

        super().__init__(repository_info, args, github_api)