示例#1
0
文件: git.py 项目: simonbray/planemo
def push(ctx, repo_path, to, branch, force=False):
    env = git_env_for(repo_path)
    cmd = ["git", "push"]
    if force:
        cmd += ["--force"]
    cmd += [to, branch]
    io.communicate(cmd, env=env)
示例#2
0
def clone_fork_branch(ctx,
                      target,
                      path,
                      remote_name=DEFAULT_REMOTE_NAME,
                      **kwds):
    """Clone, fork, and branch a repository ahead of building a pull request."""
    git.checkout(ctx,
                 target,
                 path,
                 branch=kwds.get("branch", None),
                 remote="origin",
                 from_branch="master")
    if kwds.get("fork"):
        try:
            fork(ctx, path, remote_name=remote_name, **kwds)
        except Exception:
            pass
    if 'GITHUB_USER' in os.environ:
        # On CI systems fork doesn't add a local remote under circumstances I don't quite understand,
        # but that's probably linked to https://github.com/cli/cli/issues/2722
        cmd = [
            'git', 'remote', 'add', remote_name,
            f"https://github.com/{os.environ['GITHUB_USER']}/{os.path.basename(target)}"
        ]
        try:
            communicate(cmd, cwd=path)
        except RuntimeError:
            # Can add the remote only once
            pass
    return remote_name
示例#3
0
def push(ctx, repo_path, to, branch, force=False):
    env = git_env_for(repo_path)
    cmd = ["git", "push"]
    if force:
        cmd += ["--force"]
    cmd += [to, branch]
    io.communicate(cmd, env=env)
示例#4
0
def fork(ctx, path, remote_name=DEFAULT_REMOTE_NAME, **kwds):
    """Fork the target repository using ``gh``."""
    gh_path = ensure_gh(ctx, **kwds)
    gh_env = get_gh_env(ctx, path, **kwds)
    cmd = [gh_path, "repo", "fork", '--remote=true', '--remote-name', remote_name]
    communicate(cmd, cwd=path, env=gh_env)
    return remote_name
示例#5
0
def pull_request(ctx, path, message=None, **kwds):
    """Create a pull request against the origin of the path using ``hub``."""
    hub_path = ensure_hub(ctx, **kwds)
    hub_env = get_hub_env(ctx, path, **kwds)
    cmd = [hub_path, "pull-request"]
    if message is not None:
        cmd.extend(["-m", message])
    communicate(cmd, env=hub_env)
示例#6
0
def pull_request(ctx, path, message=None, **kwds):
    """Create a pull request against the origin of the path using ``hub``."""
    hub_path = ensure_hub(ctx, **kwds)
    hub_env = get_hub_env(ctx, path, **kwds)
    cmd = [hub_path, "pull-request"]
    if message is not None:
        cmd.extend(["-m", message])
    communicate(cmd, env=hub_env)
示例#7
0
def push(ctx, repo_path, to=None, branch=None, force=False):
    env = git_env_for(repo_path)
    cmd = ["git", "push"]
    if force:
        cmd += ["--force"]
    if to and branch:
        cmd += ['-u', to, branch]
    io.communicate(cmd, env=env, cwd=repo_path)
示例#8
0
def _try_download_hub(planemo_hub_path):
    link = _hub_link()
    # Strip URL base and .tgz at the end.
    basename = link.split("/")[-1].rsplit(".", 1)[0]
    untar_to(link,
             tar_args="-zxvf - %s/bin/hub -O > '%s'" %
             (basename, planemo_hub_path))
    communicate(["chmod", "+x", planemo_hub_path])
示例#9
0
def create_repository(ctx, owner, repo, dest, dry_run, **kwds):
    gh_path = ensure_gh(ctx, **kwds)
    gh_env = get_gh_env(ctx, dry_run=dry_run, **kwds)
    cmd = [gh_path, 'repo', 'create', '-y', '--public', "{owner}/{repo}".format(owner=owner, repo=repo)]
    if dry_run:
        "Would run command '{}'".format(" ".join(cmd))
        git.init(ctx, dest)
        return dest
    communicate(cmd, env=gh_env, cwd=dest)
    return os.path.join(dest, repo)
示例#10
0
def pull_request(ctx, path, message=None, **kwds):
    """Create a pull request against the origin of the path using ``gh``."""
    gh_path = ensure_gh(ctx, **kwds)
    gh_env = get_gh_env(ctx, path, **kwds)
    cmd = [gh_path, "pr", "create"]
    if message is None:
        cmd.append('--fill')
    else:
        lines = message.splitlines()
        cmd.extend(['--title', lines[0]])
        if len(lines) > 1:
            cmd.extend(["--body", "\n".join(lines[1:])])
    communicate(cmd, env=gh_env)
示例#11
0
文件: git.py 项目: simonbray/planemo
def clone(*args, **kwds):
    """Clone a git repository.

    See :func:`command_clone` for description of arguments.
    """
    command = command_clone(*args, **kwds)
    return io.communicate(command)
示例#12
0
 def _communicate(self, command_builder):
     stdout, _ = communicate(
         command_builder.command,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE,
     )
     return stdout
示例#13
0
 def _communicate(self, command_builder):
     stdout, _ = communicate(
         command_builder.command,
         stdout=subprocess.PIPE,
         stderr=subprocess.PIPE,
     )
     return stdout
示例#14
0
文件: git.py 项目: nturaga/planemo
def clone(*args, **kwds):
    """Clone a git repository.

    See :func:`command_clone` for description of arguments.
    """
    command = command_clone(*args, **kwds)
    return io.communicate(command)
示例#15
0
def ls_remote(ctx, remote_repo):
    """Return a dictionary with refs as key and commits as value."""
    commits_and_refs = io.communicate(
        ["git", "ls-remote", remote_repo],
        stdout=subprocess.PIPE,
    )[0]
    return dict(line.split()[::-1]
                for line in commits_and_refs.decode('utf-8').splitlines())
示例#16
0
文件: config.py 项目: nturaga/planemo
 def log_contents(self):
     logs_command = docker_util.logs_command(
         **self.docker_target_kwds
     )
     output, _ = communicate(
         logs_command
     )
     return output
示例#17
0
def diff(ctx, directory, range):
    """Produce a list of diff-ed files for commit range."""
    cmd_template = "cd '%s' && git diff --name-only '%s' --"
    cmd = cmd_template % (directory, range)
    stdout, _ = io.communicate(cmd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    return [l.strip() for l in text_type(stdout).splitlines() if l]
示例#18
0
文件: git.py 项目: nturaga/planemo
def diff(ctx, directory, range):
    """Produce a list of diff-ed files for commit range."""
    cmd_template = "cd '%s' && git diff --name-only '%s' --"
    cmd = cmd_template % (directory, range)
    stdout, _ = io.communicate(
        cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    return [l.strip() for l in text_type(stdout).splitlines() if l]
示例#19
0
文件: git.py 项目: simonbray/planemo
def diff(ctx, directory, range):
    """Produce a list of diff-ed files for commit range."""
    cmd_template = "cd '%s' && git diff --name-only '%s' --"
    cmd = cmd_template % (directory, range)
    stdout, _ = io.communicate(cmd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               universal_newlines=True)
    return [line.strip() for line in unicodify(stdout).splitlines() if line]
示例#20
0
 def log_contents(self):
     logs_command = docker_util.logs_command(
         self.server_name,
         **self.docker_target_kwds
     )
     output, _ = communicate(
         logs_command
     )
     return output
示例#21
0
文件: git.py 项目: nturaga/planemo
def checkout(ctx, remote_repo, local_path, branch=None, remote="origin", from_branch="master"):
    """Checkout a new branch from a remote repository."""
    env = git_env_for(local_path)
    if not os.path.exists(local_path):
        io.communicate(command_clone(ctx, remote_repo, local_path))
    else:
        io.communicate(["git", "fetch", remote], env=env)

    if branch:
        io.communicate(["git", "checkout", "%s/%s" % (remote, from_branch), "-b", branch], env=env)
    else:
        io.communicate(["git", "merge", "--ff-only", "%s/%s" % (remote, from_branch)], env=env)
示例#22
0
文件: git.py 项目: yuanbit/planemo
def checkout(ctx, remote_repo, local_path, branch=None, remote="origin", from_branch="master"):
    """Checkout a new branch from a remote repository."""
    env = git_env_for(local_path)
    if not os.path.exists(local_path):
        io.communicate(command_clone(ctx, remote_repo, local_path))
    else:
        io.communicate(["git", "fetch", remote], env=env)

    if branch:
        io.communicate(["git", "checkout", "%s/%s" % (remote, from_branch), "-b", branch], env=env)
    else:
        io.communicate(["git", "merge", "--ff-only", "%s/%s" % (remote, from_branch)], env=env)
示例#23
0
文件: git.py 项目: simonbray/planemo
def rev(ctx, directory):
    """Raw revision for git directory specified.

    Throws ``RuntimeError`` if not a git directory.
    """
    cmd_template = "cd '%s' && git rev-parse HEAD"
    cmd = cmd_template % directory
    stdout, _ = io.communicate(cmd,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    return unicodify(stdout).strip()
示例#24
0
def test_io_capture():
    """Test :func:`planemo.io.conditionally_captured_io`."""
    with io.conditionally_captured_io(True, tee=False) as capture:
        io.warn("Problem...")
    assert_equal(capture[0]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.shell("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.communicate("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(False, tee=False) as capture:
        io.communicate("echo 'Test...'")

    assert capture is None
示例#25
0
文件: git.py 项目: davebx/planemo
def rev(ctx, directory):
    """ Raw revision for git directory specified.

    Throws ``RuntimeError`` if not a git directory.
    """
    cmd_template = "cd '%s' && git rev-parse HEAD"
    cmd = cmd_template % directory
    stdout, _ = io.communicate(
        cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE
    )
    return stdout.strip()
示例#26
0
def test_io_capture():
    """Test :func:`planemo.io.conditionally_captured_io`."""
    with io.conditionally_captured_io(True, tee=False) as capture:
        io.warn("Problem...")
    assert_equal(capture[0]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.shell("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(True, tee=False) as capture:
        io.communicate("echo 'Problem...'")
    assert_equal(capture[0]["data"], "echo 'Problem...'")
    assert_equal(capture[1]["data"], "Problem...")

    with io.conditionally_captured_io(False, tee=False) as capture:
        io.communicate("echo 'Test...'")

    assert capture is None
示例#27
0
def create_release(ctx, from_dir, target_dir, owner, repo, version, dry_run, notes="", **kwds):
    assert_new_version(ctx, version, owner=owner, repo=repo)
    target_repository_path = get_or_create_repository(ctx, owner=owner, repo=repo, dry_run=dry_run)
    add_dir_contents_to_repo(ctx, from_dir, target_dir, target_repository_path, version=version, dry_run=dry_run, notes=notes)
    gh_path = ensure_gh(ctx, **kwds)
    gh_env = get_gh_env(ctx, dry_run=dry_run, **kwds)
    cmd = [
        gh_path,
        'release',
        '-R',
        "{}/{}".format(owner, repo),
        'create',
        "v{version}".format(version=version),
        '--title',
        str(version),
    ]
    cmd.extend(['--notes', notes or changelog_in_repo(target_repository_path)])
    if not dry_run:
        communicate(cmd, env=gh_env)
    else:
        ctx.log("Would run command '{}'".format(" ".join(cmd)))
示例#28
0
def add(ctx, repo_path, file_path):
    env = git_env_for(repo_path)
    io.communicate("cd '%s' && git add '%s'" % (repo_path, os.path.abspath(file_path)), env=env)
示例#29
0
文件: git.py 项目: simonbray/planemo
def branch(ctx, repo_path, branch, from_branch=None):
    env = git_env_for(repo_path)
    cmd = ["git", "checkout", "-b", branch]
    if from_branch is not None:
        cmd.append(from_branch)
    io.communicate(cmd, env=env)
示例#30
0
def commit(ctx, repo_path, message=""):
    env = git_env_for(repo_path)
    io.communicate(["git", "commit", "-m", message], env=env)
示例#31
0
文件: git.py 项目: simonbray/planemo
def commit(ctx, repo_path, message=""):
    env = git_env_for(repo_path)
    io.communicate(["git", "commit", "-m", message], env=env)
示例#32
0
文件: git.py 项目: simonbray/planemo
def add(ctx, repo_path, file_path):
    env = git_env_for(repo_path)
    io.communicate("cd '%s' && git add '%s'" %
                   (repo_path, os.path.abspath(file_path)),
                   env=env)
示例#33
0
def add(ctx, repo_path, file_path):
    env = git_env_for(repo_path)
    io.communicate(
        ["git", "add", os.path.relpath(file_path, repo_path)],
        env=env,
        cwd=repo_path)
示例#34
0
def _try_download_hub(planemo_hub_path):
    link = _hub_link()
    # Strip URL base and .tgz at the end.
    basename = link.split("/")[-1].rsplit(".", 1)[0]
    untar_to(link, tar_args="-Ozxvf - %s/bin/hub > '%s'" % (basename, planemo_hub_path))
    communicate(["chmod", "+x", planemo_hub_path])
示例#35
0
def fork(ctx, path, **kwds):
    """Fork the target repository using ``hub``."""
    hub_path = ensure_hub(ctx, **kwds)
    hub_env = get_hub_env(ctx, path, **kwds)
    cmd = [hub_path, "fork"]
    communicate(cmd, env=hub_env)
示例#36
0
def fork(ctx, path, **kwds):
    """Fork the target repository using ``hub``."""
    hub_path = ensure_hub(ctx, **kwds)
    hub_env = get_hub_env(ctx, path, **kwds)
    cmd = [hub_path, "fork"]
    communicate(cmd, env=hub_env)
示例#37
0
def init(ctx, repo_path):
    env = git_env_for(repo_path)
    io.communicate(["git", "init"], env=env)
示例#38
0
def branch(ctx, repo_path, branch, from_branch=None):
    env = git_env_for(repo_path)
    cmd = ["git", "checkout", "-b", branch]
    if from_branch is not None:
        cmd.append(from_branch)
    io.communicate(cmd, env=env)
示例#39
0
def fork(ctx, path, **kwds):
    """Fork the target repository using ``hub``."""
    gh_path = ensure_gh(ctx, **kwds)
    gh_env = get_gh_env(ctx, path, **kwds)
    cmd = [gh_path, "repo", "fork"]
    communicate(cmd, env=gh_env)