#!/usr/bin/env python3 from git import Repo import os import subprocess # Settings branches = ["15.0", "16.0"] output_file = "modules.md" # Get current repo repo = Repo(".") # Define dictionary for module list module_data = {} # Iterate over each branch for branch in branches: # Switch to the branch repo.git.checkout(branch) # Get all submodules submdoules = repo.submodules # Iterate over each submodule for submodule in filter(lambda x: x.path not in ["odoo", "enterprise", "themes"], submdoules): if submodule.url.startswith("git@"): org = submodule.url.split(":")[1].split("/")[0] repo = submodule.url.split(":")[1].split("/")[1].replace(".git", "") elif submodule.url.startswith("https://"): org = submodule.url.replace("https://github.com/", "").split("/")[0] repo = submodule.url.replace("https://github.com/", "").split("/")[1] path = submodule.path if not org: raise ValueError(f"Org not found in {submodule.url}") # Get list of modules result = subprocess.run( ["git", "-C", path, "ls-tree", "--name-only", "-d", branch], capture_output=True, text=True, check=True ) modules = result.stdout.split("\n") # Cleanup list modules = list(filter(None, modules)) modules = list(filter(lambda x: x not in ["setup", ".github"], modules)) # Add module data to the dictionary for module in modules: module_key = f"{org}|{repo}|{module}" url = f"https://github.com/{org}/{repo}" branch_link = f" [{branch}]({url}/tree/{branch})" if module_key in module_data: module_data[module_key] += branch_link else: module_data[module_key] = branch_link # Sort mdoule data by key module_data = dict(sorted(module_data.items())) with open(output_file, "w") as f: f.write("| org | repo | name | link |\n") f.write("|---|---|---|---|\n") for key, links in module_data.items(): org, repo, name = key.split('|') f.write(f"| {org} | {repo} | {name} |{links} |\n") print(f"Markdown table created in {output_file}")