From d6c6eab02394f8727085345005abdf78a3d79fe9 Mon Sep 17 00:00:00 2001 From: Laurent Peuch Date: Fri, 29 Mar 2024 06:57:44 +0100 Subject: [PATCH] refactor(readme-generator/regen_readme_in_batch): blep, make core more readable --- readme_generator/regen_readme_in_batch.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/readme_generator/regen_readme_in_batch.py b/readme_generator/regen_readme_in_batch.py index 174ac47..a63a1e5 100644 --- a/readme_generator/regen_readme_in_batch.py +++ b/readme_generator/regen_readme_in_batch.py @@ -22,16 +22,19 @@ my_env["GIT_COMMITTER_EMAIL"] = "yunohost@yunohost.org" async def git(cmd, in_folder=None): - if not isinstance(cmd, list): cmd = cmd.split() + if in_folder: cmd = ["-C", in_folder] + cmd + cmd = ["git"] + cmd cmd = " ".join(map(shlex.quote, cmd)) print(cmd) + command = await asyncio.create_subprocess_shell(cmd, env=my_env, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT) data = await command.stdout.read() + return data.decode().strip() @@ -43,6 +46,7 @@ async def regen_readme(repository, branch): with tempfile.TemporaryDirectory() as folder: await git(["clone", f"https://{login}:{token}@github.com/{repository}", "--single-branch", "--branch", branch, folder]) + generate_READMEs(Path(folder)) await git(["add", "README*.md"], in_folder=folder) @@ -51,26 +55,29 @@ async def regen_readme(repository, branch): diff_not_empty = await asyncio.create_subprocess_shell(" ".join(["git", "diff", "HEAD", "--compact-summary"]), cwd=folder, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.STDOUT) diff_not_empty = await diff_not_empty.stdout.read() diff_not_empty = diff_not_empty.decode().strip() - if not diff_not_empty: + if diff_not_empty: print("nothing to do") return await git(["commit", "-a", "-m", "Auto-update README", "--author='yunohost-bot '"], in_folder=folder) await git(["push", "origin", branch, "--quiet"], in_folder=folder) - print(f"Updated https://github.com/{repository}") + print(f"Updated https://github.com/{repository}") if __name__ == '__main__': skip = True apps = json.load(open("../../builds/default/v3/apps.json"))["apps"] + for app, infos in apps.items(): if "github.com" not in infos["git"]["url"]: continue + if app == "dendrite": skip = False + if skip: continue - print(app) + time.sleep(2) asyncio.run(regen_readme(infos["git"]["url"].replace("https://github.com/", ""), infos["git"]["branch"]))