Skip to content

Commit eeb21e9

Browse files
committed
Streamline Legacy <-> App GitHub auth backend migrations
Signed-off-by: magic_rb <richard@brezak.sk>
1 parent 6a9394b commit eeb21e9

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

buildbot_nix/github_projects.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,9 @@ def __init__(
153153
super().__init__(**kwargs)
154154

155155
def reload_projects(self) -> None:
156-
repos: list[Any] = []
157-
158-
if self.project_cache_file.exists():
159-
repos = json.loads(self.project_cache_file.read_text())
156+
repos: list[Any] = refresh_projects(self.token.get(), self.project_cache_file)
160157

161-
refresh_projects(self.token.get(), self.project_cache_file)
158+
log.msg(repos)
162159

163160
atomic_write_file(self.project_cache_file, json.dumps(repos))
164161

@@ -569,6 +566,19 @@ def load_projects(self) -> list["GitProject"]:
569566
json.loads(self.config.project_cache_file.read_text()),
570567
key=lambda x: x["full_name"],
571568
)
569+
570+
if isinstance(self.auth_backend, GithubAppAuthBackend):
571+
dropped_repos = list(
572+
filter(lambda repo: not "installation_id" in repo, repos)
573+
)
574+
if dropped_repos:
575+
tlog.info(
576+
"Dropped projects follow, refresh will follow after initialisation:"
577+
)
578+
for dropped_repo in dropped_repos:
579+
tlog.info(f"\tDropping repo {dropped_repo['full_name']}")
580+
repos = list(filter(lambda repo: "installation_id" in repo, repos))
581+
572582
tlog.info(f"Loading {len(repos)} cached repositories.")
573583
return list(
574584
filter(
@@ -587,7 +597,16 @@ def load_projects(self) -> list["GitProject"]:
587597
)
588598

589599
def are_projects_cached(self) -> bool:
590-
return self.config.project_cache_file.exists()
600+
if not self.config.project_cache_file.exists():
601+
return False
602+
603+
all_have_installation_id = True
604+
for project in json.loads(self.config.project_cache_file.read_text()):
605+
if not "installation_id" in project:
606+
all_have_installation_id = False
607+
break
608+
609+
return all_have_installation_id
591610

592611
@property
593612
def type(self) -> str:

0 commit comments

Comments
 (0)