コード例 #1
0
async def push(config, task, repo_path, target_repo, revision=None):
    """Run `hg push` against the current source repo.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source repo path
        target_repo (str): Destination repository url
        revision (str): A specific revision to push
    Raises:
        PushError: on failure
    """
    target_repo_ssh = target_repo.replace("https://", "ssh://")
    ssh_config = config.get("hg_ssh_config", {}).get(get_ssh_user(task), {})
    ssh_username = ssh_config.get("user")
    ssh_key = ssh_config.get("keyfile")
    ssh_opt = []
    if ssh_username or ssh_key:
        ssh_opt = ["-e", "ssh"]
        if ssh_username:
            ssh_opt[1] += " -l %s" % ssh_username
        if ssh_key:
            ssh_opt[1] += " -i %s" % ssh_key
    log.info("Pushing local changes to {}".format(target_repo_ssh))
    try:
        await run_hg_command(config, "push", *ssh_opt, "-r", revision if revision else ".", "-v", target_repo_ssh, repo_path=repo_path, exception=PushError)
    except PushError as exc:
        log.warning("Hit PushError %s", str(exc))
        await strip_outgoing(config, task, repo_path)
        raise
コード例 #2
0
async def push(config, task, repo_path, target_repo):
    """Run `git push` against the current source repo.

    Args:
        config (dict): the running config
        task (dict): the running task
        repo_path (str): the source repo path
        target_repo (str): Destination repository url
        revision (str): A specific revision to push
    Raises:
        PushError: on failure
    """
    ssh_config = config.get("git_ssh_config", {}).get(get_ssh_user(task), {})
    ssh_key = ssh_config.get("keyfile")
    git_ssh_cmd = "ssh -i {}".format(ssh_key) if ssh_key else "ssh"

    repo = Repo(repo_path)
    target_repo_ssh = extract_github_repo_ssh_url(target_repo)
    repo.remote().set_url(target_repo_ssh, push=True)
    log.debug("Push using ssh command: {}".format(git_ssh_cmd))
    branch = get_branch(task, "master")
    with repo.git.custom_environment(GIT_SSH_COMMAND=git_ssh_cmd):
        log.info("Pushing local changes to {}".format(target_repo_ssh))
        push_results = repo.remote().push(branch,
                                          verbose=True,
                                          set_upstream=True)

    try:
        _check_if_push_successful(push_results)
    except PushError:
        await strip_outgoing(config, task, repo_path)
        raise

    log.info("Push done succesfully!")
コード例 #3
0
def test_get_ssh_user(task_defn, ssh_user, expected):
    if ssh_user:
        task_defn["payload"]["ssh_user"] = ssh_user
    assert ttask.get_ssh_user(task_defn) == expected