def _main(arg_strings=None):
    parser = _make_parser()
    args = parser.parse_args(arg_strings)
    version_name = "open-ce-v{}".format(args.version)
    release_number = ".".join(args.version.split(".")[:-1])
    branch_name = "open-ce-r{}".format(release_number)
    primary_repo_url = "[email protected]:{}/{}.git".format(
        args.github_org, args.primary_repo)

    version_msg = "Open-CE Version {}".format(args.version)
    release_name = "v{}".format(args.version)
    if args.code_name:
        version_msg = "{} Code-named {}".format(version_msg, args.code_name)
        release_name = "{} ({})".format(release_name, args.code_name)

    primary_repo_path = os.path.abspath(
        os.path.join(args.repo_dir, args.primary_repo))
    print("--->Making clone location: " + primary_repo_path)
    os.makedirs(primary_repo_path, exist_ok=True)
    print("--->Cloning {}".format(primary_repo_url))
    git_utils.clone_repo(primary_repo_url, primary_repo_path, args.branch)

    print("--->Creating {} branch in {}".format(version_name,
                                                args.primary_repo))
    git_utils.create_branch(primary_repo_path, branch_name)

    print("--->Updating env files.")
    _update_env_files(primary_repo_path, version_name)

    print("--->Committing env files.")
    git_utils.commit_changes(primary_repo_path,
                             "Updates for {}".format(release_number))

    print("--->Tag Primary Branch")
    git_utils.create_tag(primary_repo_path, version_name, version_msg)

    push = git_utils.ask_for_input(
        "Would you like to push changes to primary repo?")
    if push.startswith("y"):
        print("--->Pushing branch.")
        git_utils.push_branch(primary_repo_path, branch_name)
        print("--->Pushing tag.")
        git_utils.push_branch(primary_repo_path, version_name)

    tag_all_repos.tag_all_repos(github_org=args.github_org,
                                tag=version_name,
                                tag_msg=version_msg,
                                branch=args.branch,
                                repo_dir=args.repo_dir,
                                pat=args.pat,
                                skipped_repos=[args.primary_repo, ".github"] +
                                inputs.parse_arg_list(args.skipped_repos),
                                prev_tag=None)

    release = git_utils.ask_for_input(
        "Would you like to create a github release?")
    if release.startswith("y"):
        print("--->Creating Draft Release.")
        git_utils.create_release(args.github_org, args.primary_repo, args.pat,
                                 version_name, release_name, version_msg, True)
Пример #2
0
def tag_all_repos(github_org, tag, tag_msg, branch, repo_dir, pat, skipped_repos, prev_tag): # pylint: disable=too-many-arguments
    '''
    Clones, then tags all repos with a given tag, and pushes back to remote.
    These steps are performed in separate loops to make debugging easier.
    '''
    skipped_repos = inputs.parse_arg_list(skipped_repos)
    repos = git_utils.get_all_repos(github_org, pat)
    repos = [repo for repo in repos if repo["name"] not in skipped_repos ]
    print("---------------------------Cloning all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Making clone location: " + repo_path)
        os.makedirs(repo_path, exist_ok=True)
        print("--->Cloning {}".format(repo["name"]))
        git_utils.clone_repo(repo["ssh_url"], repo_path)
        if branch and git_utils.branch_exists(repo_path, branch):
            print("--->Branch '{}' exists, checking it out.".format(branch))
            git_utils.checkout(repo_path, branch)
        elif prev_tag:
            repo_branch = git_utils.get_tag_branch(repo_path, prev_tag)
            print("--->Checking out branch '{}' which contains tag '{}'.".format(repo_branch, prev_tag))
            git_utils.checkout(repo_path, repo_branch)

    print("---------------------------Tagging all Repos")
    for repo in repos:
        repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
        print("--->Tagging {}".format(repo["name"]))
        git_utils.create_tag(repo_path, tag, tag_msg)

    push = git_utils.ask_for_input("Would you like to push all tags to remote?")
    if not push.startswith("y"):
        return

    print("---------------------------Pushing all Repos")
    for repo in repos:
        try:
            repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
            print("--->Pushing {}".format(repo["name"]))
            git_utils.push_branch(repo_path, tag)
        except Exception as exc:# pylint: disable=broad-except
            print("Error encountered when trying to push {}".format(repo["name"]))
            print(exc)
            cont_tag = git_utils.ask_for_input("Would you like to continue tagging other repos?")
            if cont_tag.startswith("y"):
                continue
            raise
Пример #3
0
def _main(arg_strings=None):
    parser = make_parser()
    args = parser.parse_args(arg_strings)

    skipped_repos = inputs.parse_arg_list(args.skipped_repos)
    repos = git_utils.get_all_repos(args.github_org, args.pat)
    repos = [repo for repo in repos if repo["name"] not in skipped_repos]

    patches = [
        os.path.abspath(arg_file)
        for arg_file in inputs.parse_arg_list(args.patches)
    ]
    for repo in repos:
        try:
            print("Beginning " + repo["name"] + "---------------------------")

            repo_path = os.path.abspath(
                os.path.join(args.repo_dir, repo["name"]))
            print("--->Making clone location: " + repo_path)
            os.makedirs(repo_path, exist_ok=True)
            print("--->Cloning {}".format(repo["name"]))
            git_utils.clone_repo(repo["ssh_url"], repo_path)
            head_branch = git_utils.get_current_branch(repo_path)
            git_utils.create_branch(repo_path, args.branch)

            for patch in patches:
                print("--->Applying Patch {}".format(patch))
                git_utils.apply_patch(repo_path, patch)

            print("--->Pushing Branch")
            git_utils.push_branch(repo_path, args.branch)

            print("--->Creating PR")
            git_utils.create_pr(args.github_org, repo["name"], args.pat,
                                args.commit_msg, args.pr_msg, args.branch,
                                head_branch)

            print("---------------------------" + "Finished " + repo["name"])
        except Exception as exc:  # pylint: disable=broad-except
            print("Error encountered when trying to patch {}".format(
                repo["name"]))
            print(exc)
            cont = git_utils.ask_for_input(
                "Would you like to continue applying patches to other repos?")
            if cont.startswith("y"):
                continue
            raise
def tag_all_repos(github_org, tag, tag_msg, branch, repo_dir, pat,
                  skipped_repos, prev_tag):  # pylint: disable=too-many-arguments
    '''
    Clones, then tags all repos with a given tag, and pushes back to remote.
    These steps are performed in separate loops to make debugging easier.
    '''
    skipped_repos = inputs.parse_arg_list(skipped_repos)
    repos = git_utils.get_all_repos(github_org, pat)
    repos = [repo for repo in repos if repo["name"] in skipped_repos]

    clone_repos(repos, branch, repo_dir, prev_tag)

    tag_repos(repos, tag, tag_msg, repo_dir)

    push = git_utils.ask_for_input(
        "Would you like to push all tags to remote?")
    if not push.startswith("y"):
        return

    push_repos(repos, tag, repo_dir)
def push_repos(repos, tag, repo_dir, continue_query=True):
    '''
    Pushes a list of repos.
    '''
    print("---------------------------Pushing all Repos")
    for repo in repos:
        try:
            repo_path = os.path.abspath(os.path.join(repo_dir, repo["name"]))
            print("--->Pushing {}".format(repo["name"]))
            git_utils.push_branch(repo_path, tag)
        except Exception as exc:  # pylint: disable=broad-except
            print("Error encountered when trying to push {}".format(
                repo["name"]))
            print(exc)
            if not continue_query:
                continue
            cont_tag = git_utils.ask_for_input(
                "Would you like to continue tagging other repos?")
            if cont_tag.startswith("y"):
                continue
            raise