Exemplo n.º 1
0
def main():
    config = get_config()
    git_tool = GitTool()

    filter_group = config.group if config.group else None

    git_tool.generate_generate_config(filter_group=filter_group)
Exemplo n.º 2
0
def main():
    config = get_config()
    git_tool = GitTool()

    lst_repo = git_tool.get_source_repo_addons(
        repo_path=config.dir, add_repo_root=True
    )
    lst_repo_organization = [
        git_tool.get_transformed_repo_info_from_url(
            a.get("url"),
            repo_path=config.dir,
            get_obj=True,
            is_submodule=a.get("is_submodule"),
            sub_path=a.get("sub_path"),
            revision=a.get("revision"),
            clone_depth=a.get("clone_depth"),
        )
        for a in lst_repo
    ]

    # Update origin to new repo
    if not config.clear:
        dct_remote, dct_project, _ = git_tool.get_manifest_xml_info(
            repo_path=config.dir, add_root=True
        )
    else:
        dct_remote = {}
        dct_project = {}
    git_tool.generate_repo_manifest(
        lst_repo_organization,
        output=f"{config.dir}{config.manifest}",
        dct_remote=dct_remote,
        dct_project=dct_project,
        keep_original=True,
    )
    git_tool.generate_generate_config()
Exemplo n.º 3
0
def main():
    config = get_config()
    github_token = config.github_token
    git_tool = GitTool()
    root_repo = Repo(config.dir)

    if not github_token and not config.skip_fork:
        raise ValueError("Missing github_token")

    organization_name = config.organization
    lst_repo = git_tool.get_source_repo_addons(repo_path=config.dir,
                                               add_repo_root=True)
    lst_repo_organization = [
        git_tool.get_transformed_repo_info_from_url(
            a.get("url"),
            repo_path=config.dir,
            organization_force=organization_name,
            is_submodule=a.get("is_submodule"),
            sub_path=a.get("sub_path"),
            revision=a.get("revision"),
            clone_depth=a.get("clone_depth"),
        ) for a in lst_repo
    ]

    if not config.skip_fork:
        i = 0
        total = len(lst_repo)
        for repo in lst_repo:
            i += 1
            print(f"Nb element {i}/{total} - {repo.get('project_name')}")
            if (config.fast and repo.get("is_submodule")
                    and os.path.isdir(repo.get("path"))):
                continue
            url = repo.get("url")

            try:
                working_repo = Repo(repo.get("relative_path"))
            except git.exc.NoSuchPathError:
                # Check to fork
                # repo_info = git_tool.get_transformed_repo_info_from_url(
                #     url, organization_force="ERPLibre",
                #     is_submodule=repo.get("is_submodule"),
                #     sub_path=repo.get("sub_path"))
                git_tool.fork_repo(
                    upstream_url=url,
                    github_token=github_token,
                    organization_name="ERPLibre",
                )
                repo_info = git_tool.get_transformed_repo_info_from_url(
                    url,
                    organization_force=organization_name,
                    is_submodule=repo.get("is_submodule"),
                    sub_path=repo.get("sub_path"),
                )
                git_tool.fork_repo(
                    upstream_url=url,
                    github_token=github_token,
                    organization_name=organization_name,
                )

                # git_tool.add_and_fetch_remote(repo_info, root_repo=root_repo)
                continue

            dct_remote_name = {a.name: a for a in working_repo.remotes}
            remote_origin = dct_remote_name.get("origin")
            remote_erplibre = dct_remote_name.get("ERPLibre")
            remote_organization = dct_remote_name.get(organization_name)

            if not remote_erplibre:
                repo_info = git_tool.get_transformed_repo_info_from_url(
                    url,
                    organization_force="ERPLibre",
                    is_submodule=repo.get("is_submodule"),
                    sub_path=repo.get("sub_path"),
                )
                # git_tool.add_and_fetch_remote(repo_info)

            git_tool.fork_repo(
                url,
                github_token,
                organization_name=organization_name,
            )

            repo_info = git_tool.get_transformed_repo_info_from_url(
                url,
                organization_force=organization_name,
                is_submodule=repo.get("is_submodule"),
                sub_path=repo.get("sub_path"),
            )
            if remote_origin:
                working_repo.git.remote("remove", "origin")
            repo_info.organization = "origin"
            # try:
            #     git_tool.add_and_fetch_remote(repo_info, root_repo=root_repo)
            # except Exception as e:
            #     print(e)
            if config.force and remote_organization:
                working_repo.git.remote("remove", organization_name)

            repo_info.organization = organization_name
            # git_tool.add_and_fetch_remote(repo_info)

    # Update origin to new repo
    # git_tool.generate_git_modules(lst_repo_organization, repo_path=config.dir)
    git_tool.generate_repo_manifest(
        lst_repo_organization, output=f"{config.dir}manifest/default.dev.xml")
    git_tool.generate_generate_config()