Skip to content

Commit c9e850f

Browse files
Mic92zimbatm
authored andcommitted
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 <zimbatm@zimbatm.com>
1 parent f22c113 commit c9e850f

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

buildbot_nix/__init__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,18 @@ def setup_authz(projects: list[GithubProject], admins: list[str]) -> util.Authz:
755755
)
756756

757757

758+
class PeriodicWithStartup(schedulers.Periodic):
759+
def __init__(self, *args: Any, run_on_startup: bool = False, **kwargs: Any) -> None:
760+
super().__init__(*args, **kwargs)
761+
self.run_on_startup = run_on_startup
762+
763+
@defer.inlineCallbacks
764+
def activate(self) -> Generator[Any, object, Any]:
765+
if self.run_on_startup:
766+
yield self.setState("last_build", None)
767+
yield super().activate()
768+
769+
758770
class NixConfigurator(ConfiguratorBase):
759771
"""Janitor is a configurator which create a Janitor Builder with all needed Janitor steps"""
760772

@@ -841,11 +853,12 @@ def configure(self, config: dict[str, Any]) -> None:
841853
builderNames=["reload-github-projects"],
842854
buttonName="Update projects",
843855
),
844-
# project list twice a day
845-
schedulers.Periodic(
856+
# project list twice a day and on startup
857+
PeriodicWithStartup(
846858
name="reload-github-projects-bidaily",
847859
builderNames=["reload-github-projects"],
848860
periodicBuildTimer=12 * 60 * 60,
861+
run_on_startup=not self.github.project_cache_file.exists(),
849862
),
850863
],
851864
)

buildbot_nix/github_projects.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ def refresh_projects(github_token: str, repo_cache_file: Path) -> None:
186186

187187
def load_projects(github_token: str, repo_cache_file: Path) -> list[GithubProject]:
188188
if not repo_cache_file.exists():
189-
log.msg("fetching github repositories")
190-
refresh_projects(github_token, repo_cache_file)
191-
repos: list[dict[str, Any]] = json.loads(repo_cache_file.read_text())
189+
return []
190+
191+
repos: list[dict[str, Any]] = sorted(
192+
json.loads(repo_cache_file.read_text()), key=lambda x: x["full_name"]
193+
)
192194
return [GithubProject(repo) for repo in repos]

0 commit comments

Comments
 (0)