コード例 #1
0
def commit_updates(bundle_path, update_info):
    working_directory = os.path.abspath(os.getcwd())
    message = ["Automated update by Adabot (adafruit/adabot@{})"
               .format(repo_version())]
    os.chdir(bundle_path)
    for url, old_commit, new_commit, summary in update_info:
        url_parts = url.split("/")
        user, repo = url_parts[-2:]
        summary = summary.replace("#", "{}/{}#".format(user, repo))
        message.append("Updating {} to {} from {}:\n{}".format(url,
                                                               new_commit,
                                                               old_commit,
                                                               summary))
    message = "\n\n".join(message)
    git.add(".")
    git.commit(message=message)
    os.chdir(working_directory)
コード例 #2
0
def update_page(filename, branch):
    info('Updating page ' + filename)
    with open(filename, 'w') as fh:
        list_gerrits(fh, branch)
    git.add(filename)
コード例 #3
0
ファイル: snap.py プロジェクト: ChrisMacNaughton/jenkins
def _create_branch(repo, from_branch, to_branch, dry_run, force, patches):
    """ Creates a git branch based on the upstream snap repo and a version to branch as. This will also update
    the snapcraft.yaml with the correct version to build the snap from in that particular branch.

    These branches must already exist in https://github.com/kubernetes/kubernetes.

    Usage:

    snap.py branch --repo git+ssh://[email protected]/snap-kubectl \
      --from-branch master \
      --to-branch 1.13.2
    """
    env = os.environ.copy()

    if branch_exists(repo, to_branch, env) and not force:
        click.echo(f"{to_branch} already exists, skipping...")
        sys.exit(0)

    snap_basename = urlparse(repo)
    snap_basename = Path(snap_basename.path).name
    if snap_basename.endswith(".git"):
        snap_basename = snap_basename.rstrip(".git")
    tmpdir = tempfile.TemporaryDirectory()
    snap_basename = tmpdir.name
    capture(["git", "clone", repo, snap_basename])
    capture(["git", "remote", "prune", "origin"], cwd=snap_basename)
    capture(["git", "config" "user.email", "*****@*****.**"], cwd=snap_basename)
    capture(["git", "config", "user.name", "cdkbot"], cwd=snap_basename)
    capture(["git", "checkout", "-b", to_branch], cwd=snap_basename)

    snapcraft_fn = Path(snap_basename) / "snapcraft.yaml"
    snapcraft_fn_tpl = Path(snap_basename) / "snapcraft.yaml.in"
    if not snapcraft_fn_tpl.exists():
        click.echo(f"{snapcraft_fn_tpl} not found")
        sys.exit(1)

    # Apply patches
    patches_list = []
    if patches:
        patches_path = Path(patches)
        if patches_path.exists():
            click.echo("Patches found, applying.")
            patches_map = yaml.safe_load(patches_path.read_text(encoding="utf8"))
            # TODO: cleanup
            if "all" in patches_map:
                for patch_fn in patches_map["all"]:
                    patch_fn = Path(patch_fn).absolute()
                    shared_path = str(Path("shared") / patch_fn.parts[-1])
                    sh.cp(str(patch_fn), str(shared_path), _cwd=snap_basename)
                    patches_list.append(shared_path)
                    git.add(shared_path, _cwd=snap_basename)
            if to_branch.lstrip("v") in patches_map:
                for patch_fn in patches_map[to_branch.lstrip("v")]:
                    patch_fn = Path(patch_fn).absolute()
                    shared_path = str(Path("shared") / patch_fn.parts[-1])
                    sh.cp(str(patch_fn), str(shared_path), _cwd=snap_basename)
                    patches_list.append(shared_path)
                    git.add(shared_path, _cwd=snap_basename)

    k8s_major_minor = semver.parse(to_branch.lstrip("v"))
    k8s_major_minor = f"{k8s_major_minor['major']}.{k8s_major_minor['minor']}"

    snapcraft_yml = snapcraft_fn_tpl.read_text()
    snapcraft_yml = _render(
        snapcraft_fn_tpl,
        {
            "snap_version": to_branch.lstrip("v"),
            "patches": patches_list,
            "go_version": K8S_GO_MAP.get(k8s_major_minor, "go/1.12/stable"),
        },
    )
    snapcraft_fn.write_text(snapcraft_yml)
    if not dry_run:
        cmd_ok("git add .", cwd=snap_basename)
        cmd_ok(f"git commit -m 'Creating branch {to_branch}'", cwd=snap_basename)
        cmd_ok(f"git push --force {repo} {to_branch}", cwd=snap_basename)