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_install_locally()
def main(): config = get_config() git_tool = GitTool() lst_repo = git_tool.get_source_repo_addons(repo_path=config.dir, add_repo_root=False) 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 ] lst_ignore_repo = ["odoo"] i = 0 total = len(lst_repo) branch_name = "12.0_dev" for repo in lst_repo_organization: i += 1 print(f"\nNb element {i}/{total} - {repo.path}") is_checkout_branch = False if repo.repo_name in lst_ignore_repo: print(f"Ignore {repo.repo_name}.") continue git_repo = Repo(repo.relative_path) # Force checkout branch if exist try: git_repo.git.checkout(branch_name) is_checkout_branch = True except GitCommandError: try: git_repo.git.checkout("-t", f"{repo.organization}/{branch_name}") is_checkout_branch = True except GitCommandError: pass has_change = get_manifest_external_dependencies(repo) if has_change: if not is_checkout_branch: git_repo.git.checkout("-b", branch_name) # change branch, commit and push git_repo.git.add(".") git_repo.git.commit("-m", "Set all module auto_install at False") git_repo.git.push("-u", repo.organization, branch_name)
def main(): config = get_config() github_token = config.github_token git_tool = GitTool() if not github_token: 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 ] url_not_found_count = 0 url_found_count = 0 i = 0 total = len(lst_repo_organization) for repo in lst_repo_organization: i += 1 print(f"Nb element {i}/{total} - {repo.project_name}") url = repo.url status = git_tool.get_pull_request_repo( upstream_url=url, github_token=github_token, organization_name=organization_name, ) if status is False: url_not_found_count += 1 else: url_found_count += len(status) print(f"Repository not found: {url_not_found_count}") print(f"URL found: {url_found_count}")
def main(): config = get_config() git_tool = GitTool() lst_repo = git_tool.get_source_repo_addons(repo_path=config.dir, add_repo_root=False) 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 ] i = 0 total = len(lst_repo) for repo in lst_repo_organization: i += 1 print(f"\nNb element {i}/{total} - {repo.path}") # TODO validate with default to ignore duplicate url, if same remote repo if not repo.is_submodule: continue upstream_name = f"ERPLibre_update_12/{git_tool.default_branch}" remote_branch_name = f"{upstream_name}/{git_tool.default_branch}" git_repo = Repo(repo.relative_path) # 1. Add remote if not exist try: upstream_remote = git_repo.remote(upstream_name) print(f'Remote "{upstream_name}" already exists in' f" {repo.relative_path}") except ValueError: upstream_remote = retry(wait_exponential_multiplier=1000, stop_max_delay=15000)( git_repo.create_remote)(upstream_name, repo.url_https) print('Remote "%s" created for %s' % (upstream_name, repo.url_https)) # 2. Fetch the remote source retry(wait_exponential_multiplier=1000, stop_max_delay=15000)(upstream_remote.fetch)() print('Remote "%s" fetched' % upstream_name) # 3. Rebase actual branch with new branch rev = repo.revision if repo.revision else git_tool.default_branch try: git_repo.git.checkout(rev) except: if repo.revision: rev = f"{repo.original_organization}/{repo.revision}" else: rev = f"{repo.original_organization}/{git_tool.default_branch}" git_repo.git.checkout("--track", rev) actual_commit = git_repo.git.rev_parse("HEAD") try: git_repo.git.rebase(remote_branch_name) except Exception as e: print(e, file=sys.stderr) new_commit = git_repo.git.rev_parse("HEAD") if actual_commit == new_commit: print("== No diff ==") else: print(f"== Old commit {actual_commit} - new commit {new_commit}") # push try: retry(wait_exponential_multiplier=1000, stop_max_delay=15000)( git_repo.git.push)(repo.organization, rev) except: print( "Cannot push, maybe need to push force or resolv rebase" " conflict", file=sys.stderr, ) print(f"cd {repo.path}") print(f"git diff ERPLibre/v#.#.#..HEAD") print(f"git push --force {repo.organization} {rev}") print(f"cd -")
def main(): config = get_config() github_token = config.github_token git_tool = GitTool() root_repo = Repo(config.dir) if not github_token: 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")) for a in lst_repo ] i = 0 total = len(lst_repo) for repo in lst_repo: i += 1 print(f"Nb element {i}/{total}") 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 config.skip_fork: 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_odoo_install_locally()
def main(): config = get_config() github_token = config.github_token if not github_token: raise ValueError("Missing github_token") repo_root = Repo(config.dir) lst_repo = GitTool().get_source_repo_addons(repo_path=config.dir) i = 0 total = len(lst_repo) for repo in lst_repo: i += 1 print(f"Nb element {i}/{total}") url = repo.get("url") repo_dir_root = repo.get("path") branch_name = None upstream_name = "upstream" organization_name = config.organization # Exception, if repo existing, create appropriate remote to keep access # and remove origin # TODO do it # Don't overwrite upstream_name if already exist # Create origin of organization of upstream if not exist # Move actual origin to is organization working_repo = Repo(repo.get("relative_path")) dct_remote_name = {a.name: a for a in working_repo.remotes} remote_origin = dct_remote_name.get("origin") # for remote in working_repo.remotes: if remote_origin: repo_origin_info = GitTool.get_transformed_repo_info_from_url( remote_origin.url, repo_path=repo.get("relative_path")) if repo_origin_info.organization not in dct_remote_name.keys(): # Add remote upstream_remote = retry(wait_exponential_multiplier=1000, stop_max_delay=15000)( working_repo.create_remote)( repo_origin_info.organization, repo_origin_info.url_https) print('Remote "%s" created for %s' % ( repo_origin_info.organization, repo_origin_info.url_https, )) # Fetch the remote retry(wait_exponential_multiplier=1000, stop_max_delay=15000)(upstream_remote.fetch)() print('Remote "%s" fetched' % repo_origin_info.organization) # working_repo.git.remote.remove("origin") upstream_name = organization_name # TODO a la première création, on choisit le URL source en cas de non existance de upstream, # sinon on choisit celui de ERPLibre # [<git.Remote "origin">, <git.Remote "upstream">, <git.Remote "MathBenTech">] _logger.info(f"Fork {url} on dir {repo_dir_root} for organization" f" {organization_name}") fork_github_repo.fork_and_clone_repo( url, github_token, repo_dir_root, branch_name=branch_name, upstream_name=upstream_name, organization_name=organization_name, # fork_only=True, repo_root=repo_root, ) # Update origin to new repo GitTool().generate_generate_config()
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()