From c9e850ff32650e7bbb5d169707b7b142c3a3e88b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Mon, 8 Jan 2024 08:10:03 +0100 Subject: [PATCH] only refresh github projects in timer and sort them This way errors are more visible to users on the first running. Co-authored-by: zimbatm --- buildbot_nix/__init__.py | 17 +++++++++++++++-- buildbot_nix/github_projects.py | 8 +++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/buildbot_nix/__init__.py b/buildbot_nix/__init__.py index 3a742eb..34ae933 100644 --- a/buildbot_nix/__init__.py +++ b/buildbot_nix/__init__.py @@ -755,6 +755,18 @@ def setup_authz(projects: list[GithubProject], admins: list[str]) -> util.Authz: ) +class PeriodicWithStartup(schedulers.Periodic): + def __init__(self, *args: Any, run_on_startup: bool = False, **kwargs: Any) -> None: + super().__init__(*args, **kwargs) + self.run_on_startup = run_on_startup + + @defer.inlineCallbacks + def activate(self) -> Generator[Any, object, Any]: + if self.run_on_startup: + yield self.setState("last_build", None) + yield super().activate() + + class NixConfigurator(ConfiguratorBase): """Janitor is a configurator which create a Janitor Builder with all needed Janitor steps""" @@ -841,11 +853,12 @@ class NixConfigurator(ConfiguratorBase): builderNames=["reload-github-projects"], buttonName="Update projects", ), - # project list twice a day - schedulers.Periodic( + # project list twice a day and on startup + PeriodicWithStartup( name="reload-github-projects-bidaily", builderNames=["reload-github-projects"], periodicBuildTimer=12 * 60 * 60, + run_on_startup=not self.github.project_cache_file.exists(), ), ], ) diff --git a/buildbot_nix/github_projects.py b/buildbot_nix/github_projects.py index 2c703f6..67ae791 100644 --- a/buildbot_nix/github_projects.py +++ b/buildbot_nix/github_projects.py @@ -186,7 +186,9 @@ def refresh_projects(github_token: str, repo_cache_file: Path) -> None: def load_projects(github_token: str, repo_cache_file: Path) -> list[GithubProject]: if not repo_cache_file.exists(): - log.msg("fetching github repositories") - refresh_projects(github_token, repo_cache_file) - repos: list[dict[str, Any]] = json.loads(repo_cache_file.read_text()) + return [] + + repos: list[dict[str, Any]] = sorted( + json.loads(repo_cache_file.read_text()), key=lambda x: x["full_name"] + ) return [GithubProject(repo) for repo in repos]