1
0
Fork 0

update_app_levels: Use get_apps_repo

This commit is contained in:
Félix Piédallu 2024-08-11 18:23:46 +02:00 committed by Salamandar
parent 5613dcb86d
commit 73195bc785

View file

@ -3,6 +3,7 @@
Update app catalog: commit, and create a merge request Update app catalog: commit, and create a merge request
""" """
import sys
import argparse import argparse
import logging import logging
import tempfile import tempfile
@ -17,12 +18,16 @@ import tomlkit
import tomlkit.items import tomlkit.items
from git import Repo from git import Repo
# add apps/tools to sys.path
sys.path.insert(0, str(Path(__file__).parent.parent))
from appslib import get_apps_repo
APPS_REPO = "YunoHost/apps" APPS_REPO = "YunoHost/apps"
CI_RESULTS_URL = "https://ci-apps.yunohost.org/ci/api/results" CI_RESULTS_URL = "https://ci-apps.yunohost.org/ci/api/results"
REPO_APPS_ROOT = Path(Repo(__file__, search_parent_directories=True).working_dir) TOOLS_DIR = Path(__file__).resolve().parent.parent
TOOLS_DIR = REPO_APPS_ROOT / "tools"
def github_token() -> Optional[str]: def github_token() -> Optional[str]:
@ -206,49 +211,49 @@ def main():
parser.add_argument("--commit", action=argparse.BooleanOptionalAction, default=True) parser.add_argument("--commit", action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("--pr", action=argparse.BooleanOptionalAction, default=True) parser.add_argument("--pr", action=argparse.BooleanOptionalAction, default=True)
parser.add_argument("-v", "--verbose", action=argparse.BooleanOptionalAction) parser.add_argument("-v", "--verbose", action=argparse.BooleanOptionalAction)
get_apps_repo.add_args(parser)
args = parser.parse_args() args = parser.parse_args()
logging.getLogger().setLevel(logging.INFO) logging.getLogger().setLevel(logging.INFO)
if args.verbose: if args.verbose:
logging.getLogger().setLevel(logging.DEBUG) logging.getLogger().setLevel(logging.DEBUG)
with tempfile.TemporaryDirectory(prefix="update_app_levels_") as tmpdir: repo_path = get_apps_repo.from_args(args)
logging.info("Cloning the repository...")
apps_repo = Repo.clone_from(f"git@github.com:{APPS_REPO}", to_path=tmpdir)
assert apps_repo.working_tree_dir is not None
apps_toml_path = Path(apps_repo.working_tree_dir) / "apps.toml"
# Load the app catalog and filter out the non-working ones apps_repo = Repo(repo_path)
catalog = tomlkit.load(apps_toml_path.open("r", encoding="utf-8")) apps_toml_path = repo_path / "apps.toml"
new_branch = apps_repo.create_head("update_app_levels", apps_repo.refs.master) # Load the app catalog and filter out the non-working ones
apps_repo.head.reference = new_branch catalog = tomlkit.load(apps_toml_path.open("r", encoding="utf-8"))
logging.info("Retrieving the CI results...") new_branch = apps_repo.create_head("update_app_levels", apps_repo.refs.master)
ci_results = get_ci_results() apps_repo.head.reference = new_branch
# Now compute changes, then update the catalog logging.info("Retrieving the CI results...")
changes = list_changes(catalog, ci_results) ci_results = get_ci_results()
pr_body = pretty_changes(changes)
catalog = update_catalog(catalog, ci_results)
# Save the new catalog # Now compute changes, then update the catalog
updated_catalog = tomlkit.dumps(catalog) changes = list_changes(catalog, ci_results)
updated_catalog = updated_catalog.replace(",]", " ]") pr_body = pretty_changes(changes)
apps_toml_path.open("w", encoding="utf-8").write(updated_catalog) catalog = update_catalog(catalog, ci_results)
if args.commit: # Save the new catalog
logging.info("Committing and pushing the new catalog...") updated_catalog = tomlkit.dumps(catalog)
apps_repo.index.add("apps.toml") updated_catalog = updated_catalog.replace(",]", " ]")
apps_repo.index.commit("Update app levels according to CI results") apps_toml_path.open("w", encoding="utf-8").write(updated_catalog)
apps_repo.git.push("--set-upstream", "origin", new_branch)
if args.verbose: if args.commit:
print(pr_body) logging.info("Committing and pushing the new catalog...")
apps_repo.index.add("apps.toml")
apps_repo.index.commit("Update app levels according to CI results")
apps_repo.git.push("--set-upstream", "origin", new_branch)
if args.pr: if args.verbose:
logging.info("Opening a pull request...") print(pr_body)
make_pull_request(pr_body)
if args.pr:
logging.info("Opening a pull request...")
make_pull_request(pr_body)
if __name__ == "__main__": if __name__ == "__main__":