Esempio n. 1
0
File: sync.py Progetto: nilium/tsrc
def main(args):
    workspace = tsrc.cli.get_workspace(args)
    manifest = workspace.update_manifest()
    workspace.clone_missing(manifest)
    errors = list()
    num_repos = len(manifest.repos)
    on_bad_branch = list()
    # Fetch then merge the remote tracking branch if it's
    # fast-forward
    # Display a warning if current branch is not the one
    # of the manifest
    for i, repo, full_path in workspace.enumerate_repos():
        ui.info_count(i, num_repos, "Sync", ui.bold, repo.src)
        current_branch = None
        try:
            current_branch = tsrc.git.get_current_branch(full_path)
            tsrc.git.run_git(full_path, "fetch", "--tags", "--prune", "origin")
            tsrc.git.run_git(full_path, "merge", "--ff-only", "@{u}")
        except tsrc.Error:
            errors.append(repo.src)
        if current_branch and current_branch != repo.branch:
            on_bad_branch.append((repo.src, current_branch, repo.branch))
    workspace.copy_files(manifest)
    display_bad_branches(on_bad_branch)
    if errors:
        ui.error(ui.cross, "Sync failed")
        for error in errors:
            ui.info("*", ui.bold, error)
        sys.exit(1)
    else:
        ui.info("Done", ui.check)
Esempio n. 2
0
File: push.py Progetto: nilium/tsrc
    def handle_merge_request(self):
        active_users = self.gl_helper.get_active_users()
        assignee = None
        if self.args.assignee:
            assignee = get_assignee(active_users, self.args.assignee)
            ui.info_2("Assigning to", assignee["name"])

        merge_request = self.ensure_merge_request()

        title = self.handle_title(merge_request)

        params = {
            "title": title,
            "target_branch": self.target_branch,
            "remove_source_branch": True,
        }
        if assignee:
            params["assignee_id"] = assignee["id"]

        self.gl_helper.update_merge_request(merge_request, **params)

        if self.args.accept:
            self.gl_helper.accept_merge_request(merge_request)

        ui.info(ui.green, "::",
                ui.reset, "See merge request at", merge_request["web_url"])
Esempio n. 3
0
def main(args):
    workspace_path = args.workspace_path or os.getcwd()
    workspace = tsrc.workspace.Workspace(path.Path(workspace_path))
    ui.info_1("Creating new workspace in", ui.bold, workspace_path)
    workspace.init_manifest(args.manifest_url, branch=args.branch)
    manifest = workspace.load_manifest()
    workspace.clone_missing(manifest)
    workspace.set_remotes()
    workspace.copy_files(manifest)
    ui.info("Done", ui.check)
Esempio n. 4
0
def test_info_stdout_is_not_a_tty(dumb_tty):
    ui.info(ui.red,
            "this is red",
            ui.reset,
            ui.green,
            "this is green",
            fileobj=dumb_tty)
    expected = "this is red this is green\n"
    actual = dumb_tty.getvalue()
    assert_equal_strings(actual, expected)
Esempio n. 5
0
def test_info_stdout_is_a_tty(smart_tty):
    ui.info(ui.red,
            "this is red",
            ui.reset,
            ui.green,
            "this is green",
            fileobj=smart_tty)
    expected = (RED + "this is red " + RESET + GREEN + "this is green" +
                RESET + "\n")
    actual = smart_tty.getvalue()
    assert_equal_strings(actual, expected)
Esempio n. 6
0
 def accept_merge_request(self, merge_request):
     project_id = merge_request["project_id"]
     merge_request_iid = merge_request["iid"]
     ui.info_2("Merging when build succeeds", ui.ellipsis, end="")
     url = "/projects/%s/merge_requests/%s/merge" % (project_id,
                                                     merge_request_iid)
     data = {
         "merge_when_pipeline_succeeds": True,
     }
     self.make_request("PUT", url, data=data)
     ui.info("done", ui.check)
Esempio n. 7
0
 def create_merge_request(self,
                          project_id,
                          source_branch,
                          *,
                          title,
                          target_branch="master"):
     ui.info_2("Creating merge request", ui.ellipsis, end="")
     url = "/projects/%i/merge_requests" % project_id
     data = {
         "source_branch": source_branch,
         "target_branch": target_branch,
         "title": title,
         "project_id": project_id,
     }
     result = self.make_request("POST", url, data=data)
     ui.info("done", ui.check)
     return result
Esempio n. 8
0
def main(args):
    tsrc_distribution = pkg_resources.get_distribution("tsrc")
    # pylint: disable=no-member
    version = tsrc_distribution.version
    location = path.Path(tsrc_distribution.location)
    dirty = False
    short_hash = None
    rc, out = tsrc.git.run_git(location,
                               "rev-parse",
                               "--short",
                               "HEAD",
                               raises=False)
    if rc == 0:
        short_hash = out
        dirty = tsrc.git.is_dirty(location)
    message = "tsrc version %s" % version
    if short_hash:
        message += " - git: %s" % short_hash
        if dirty:
            message += " (dirty)"
    ui.info(message)
Esempio n. 9
0
def display_statuses(statuses, errors):
    if not statuses:
        return
    max_src = max((len(x.src) for x in statuses))
    for status in statuses:
        message = (ui.green, "*", ui.reset, ui.bold, status.src.ljust(max_src),
                   ui.reset, ui.green, status.branch)
        if status.dirty:
            message = message + (ui.reset, ui.brown, "(dirty)")
        ui.info(*message)
    ui.info()

    if errors:
        ui.error("Errors when getting branch")
        for src, error in errors:
            ui.info("*", ui.bold, src, ui.reset, error.output)
        ui.info()
Esempio n. 10
0
def collect_statuses(workspace, repos):
    errors = list()
    result = list()

    if not repos:
        return errors, result

    num_repos = len(repos)
    max_len = max((len(x.src) for x in repos))
    for i, repo, full_path in workspace.enumerate_repos():
        ui.info_count(i, num_repos,
                      "Checking", repo.src.ljust(max_len + 1), end="\r")
        try:
            branch = tsrc.git.get_current_branch(full_path)
        except tsrc.git.GitError as e:
            errors.append((repo.src, e))
            continue

        dirty = tsrc.git.is_dirty(full_path)

        result.append(Status(src=repo.src, branch=branch, dirty=dirty))

    ui.info("")
    return result, errors
Esempio n. 11
0
def main(args):
    workspace = tsrc.cli.get_workspace(args)
    errors = list()
    for _, repo, full_path in workspace.enumerate_repos():
        ui.info_2("Running", "`%s`" % args.cmd_as_str, "on", ui.bold, repo.src)
        returncode = subprocess.call(args.cmd, cwd=full_path, shell=args.shell)
        if returncode != 0:
            errors.append(repo.src)
    if errors:
        ui.info(ui.cross, ui.red, "foreach failed")
        for error in errors:
            ui.info("*", ui.bold, error)
        sys.exit(1)
    else:
        ui.info(ui.check, "All done")
Esempio n. 12
0
File: log.py Progetto: nilium/tsrc
def main(args):
    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_git(full_path, *cmd, raises=False)
        if rc != 0:
            all_ok = False
        if out:
            ui.info(ui.bold, repo.src)
            ui.info(ui.bold, "-" * len(repo.src))
            ui.info(out)
    if not all_ok:
        sys.exit(1)
Esempio n. 13
0
def test_info_characters(smart_tty):
    ui.info("Doing stuff", ui.ellipsis, "sucess", ui.check, fileobj=smart_tty)
    actual = smart_tty.getvalue()
    expected = "Doing stuff " + RESET + "…" + " sucess " + GREEN + "✓"
    assert_equal_strings(actual, expected)
Esempio n. 14
0
def test_update_title(smart_tty):
    ui.info("Something", ui.bold, "bold", fileobj=smart_tty, update_title=True)
    expected = (BEGIN_TITLE + "Something bold" + END_TITLE + "Something " +
                BOLD + "bold" + RESET + "\n")
    actual = smart_tty.getvalue()
    assert_equal_strings(actual, expected)