From 2edf6860b0ee86e6b844a5e18b3849aea702ffa7 Mon Sep 17 00:00:00 2001 From: phaer Date: Thu, 26 Oct 2023 14:54:01 +0200 Subject: [PATCH] allow github projects with "." in their name --- buildbot_nix/__init__.py | 5 +++-- buildbot_nix/github_projects.py | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/buildbot_nix/__init__.py b/buildbot_nix/__init__.py index c1f6a27..54fc72d 100644 --- a/buildbot_nix/__init__.py +++ b/buildbot_nix/__init__.py @@ -25,6 +25,7 @@ from .github_projects import ( # noqa: E402 create_project_hook, load_projects, refresh_projects, + slugify_project_name ) from twisted.internet import defer, threads from twisted.python.failure import Failure @@ -63,7 +64,7 @@ class BuildTrigger(Trigger): "github.base.repo.full_name", build_props.getProperty("github.repository.full_name"), ) - project_id = repo_name.replace("/", "-") + project_id = slugify_project_name(repo_name) source = f"nix-eval-{project_id}" sch = self.schedulerNames[0] @@ -151,7 +152,7 @@ class NixEvalCommand(buildstep.ShellMixin, steps.BuildStep): "github.base.repo.full_name", build_props.getProperty("github.repository.full_name"), ) - project_id = repo_name.replace("/", "-") + project_id = slugify_project_name(repo_name) scheduler = f"{project_id}-nix-build" filtered_jobs = [] for job in jobs: diff --git a/buildbot_nix/github_projects.py b/buildbot_nix/github_projects.py index 6dfa335..ddfc0bd 100644 --- a/buildbot_nix/github_projects.py +++ b/buildbot_nix/github_projects.py @@ -69,6 +69,10 @@ def paginated_github_request(url: str, token: str) -> list[dict[str, Any]]: return items +def slugify_project_name(name: str) -> str: + return name.replace(".", "-").replace("/", "-") + + class GithubProject: def __init__(self, data: dict[str, Any]) -> None: self.data = data @@ -91,8 +95,7 @@ class GithubProject: @property def id(self) -> str: - n = self.data["full_name"] - return n.replace("/", "-") + return slugify_project_name(self.data["full_name"]) @property def default_branch(self) -> str: