From 56899cd29cc5efd3bcd78e11f843b12138e872a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 30 Apr 2024 17:38:50 +0200 Subject: [PATCH 1/3] fix printing errors in project reload hooks --- buildbot_nix/gitea_projects.py | 10 ++++++---- buildbot_nix/github_projects.py | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/buildbot_nix/gitea_projects.py b/buildbot_nix/gitea_projects.py index b343e8b..a951f95 100644 --- a/buildbot_nix/gitea_projects.py +++ b/buildbot_nix/gitea_projects.py @@ -5,7 +5,7 @@ from collections.abc import Generator from dataclasses import dataclass from pathlib import Path from tempfile import NamedTemporaryFile -from typing import Any +from typing import Any, TYPE_CHECKING from buildbot.config.builder import BuilderConfig from buildbot.plugins import util @@ -20,6 +20,9 @@ from twisted.internet import defer, threads from twisted.python import log from twisted.python.failure import Failure +if TYPE_CHECKING: + from buildbot.process.log import StreamLog + from .common import ( http_request, paginated_github_request, @@ -259,9 +262,8 @@ class ReloadGiteaProjects(BuildStep): os.kill(os.getpid(), signal.SIGHUP) return util.SUCCESS else: - yield self.addLog("log").addStderr( - f"Failed to reload project list: {self.error_msg}" - ) + log: StreamLog = yield self.addLog("log") + log.addStderr(f"Failed to reload project list: {self.error_msg}") return util.FAILURE diff --git a/buildbot_nix/github_projects.py b/buildbot_nix/github_projects.py index ded8dd1..a2c2ef8 100644 --- a/buildbot_nix/github_projects.py +++ b/buildbot_nix/github_projects.py @@ -5,7 +5,7 @@ from collections.abc import Generator from dataclasses import dataclass from pathlib import Path from tempfile import NamedTemporaryFile -from typing import Any +from typing import TYPE_CHECKING, Any from buildbot.config.builder import BuilderConfig from buildbot.plugins import util @@ -20,6 +20,9 @@ from twisted.internet import defer, threads from twisted.python import log from twisted.python.failure import Failure +if TYPE_CHECKING: + from buildbot.process.log import StreamLog + from .common import ( http_request, paginated_github_request, @@ -57,9 +60,8 @@ class ReloadGithubProjects(BuildStep): os.kill(os.getpid(), signal.SIGHUP) return util.SUCCESS else: - yield self.addLog("log").addStderr( - f"Failed to reload project list: {self.error_msg}" - ) + log: StreamLog = yield self.addLog("log") + log.addStderr(f"Failed to reload project list: {self.error_msg}") return util.FAILURE From 993b5e822a1f43d7fbd1119fe216a45b565e114b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 30 Apr 2024 17:55:27 +0200 Subject: [PATCH 2/3] log worker name on startup --- buildbot_nix/worker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/buildbot_nix/worker.py b/buildbot_nix/worker.py index 31ae821..215bd24 100644 --- a/buildbot_nix/worker.py +++ b/buildbot_nix/worker.py @@ -49,6 +49,7 @@ def setup_worker( numcpus = None allow_shutdown = None + print(f"Starting worker {workername}") s = Worker( None, None, From 4f78c6e7f79b936c8169c0ec4ad379a9d304a208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Tue, 30 Apr 2024 18:03:03 +0200 Subject: [PATCH 3/3] gitea: expect full instance url --- buildbot_nix/gitea_projects.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/buildbot_nix/gitea_projects.py b/buildbot_nix/gitea_projects.py index a951f95..995f30f 100644 --- a/buildbot_nix/gitea_projects.py +++ b/buildbot_nix/gitea_projects.py @@ -5,7 +5,8 @@ from collections.abc import Generator from dataclasses import dataclass from pathlib import Path from tempfile import NamedTemporaryFile -from typing import Any, TYPE_CHECKING +from typing import TYPE_CHECKING, Any +from urllib.parse import urlparse from buildbot.config.builder import BuilderConfig from buildbot.plugins import util @@ -69,7 +70,7 @@ class GiteaProject(GitProject): webhook_url: str, ) -> None: hooks = paginated_github_request( - f"https://{self.config.instance_url}/api/v1/repos/{owner}/{repo}/hooks?limit=100", + f"{self.config.instance_url}/api/v1/repos/{owner}/{repo}/hooks?limit=100", self.config.token(), ) config = dict( @@ -96,14 +97,15 @@ class GiteaProject(GitProject): return http_request( - f"https://{self.config.instance_url}/api/v1/repos/{owner}/{repo}/hooks", + f"{self.config.instance_url}/api/v1/repos/{owner}/{repo}/hooks", method="POST", headers=headers, data=data, ) def get_project_url(self) -> str: - return f"https://git:%(secret:{self.config.token_secret_name})s@{self.config.instance_url}/{self.name}" + url = urlparse(self.config.instance_url) + return f"{url.scheme}://git:%(secret:{self.config.token_secret_name})s@{url.hostname}/{self.name}" @property def pretty_type(self) -> str: @@ -170,7 +172,7 @@ class GiteaBackend(GitBackend): def create_reporter(self) -> ReporterBase: return GiteaStatusPush( - "https://" + self.config.instance_url, + self.config.instance_url, Interpolate(self.config.token()), context=Interpolate("buildbot/%(prop:status_name)s"), context_pr=Interpolate("buildbot/%(prop:status_name)s"), @@ -187,7 +189,7 @@ class GiteaBackend(GitBackend): def create_auth(self) -> AuthBase: assert self.config.oauth_id is not None, "Gitea requires an OAuth ID to be set" return GiteaAuth( - "https://" + self.config.instance_url, + self.config.instance_url, self.config.oauth_id, self.config.oauth_secret(), ) @@ -271,7 +273,7 @@ def refresh_projects(config: GiteaConfig, repo_cache_file: Path) -> None: repos = [] for repo in paginated_github_request( - f"https://{config.instance_url}/api/v1/user/repos?limit=100", + f"{config.instance_url}/api/v1/user/repos?limit=100", config.token(), ): if not repo["permissions"]["admin"]: @@ -283,7 +285,7 @@ def refresh_projects(config: GiteaConfig, repo_cache_file: Path) -> None: try: # Gitea doesn't include topics in the default repo listing, unlike GitHub topics: list[str] = http_request( - f"https://{config.instance_url}/api/v1/repos/{repo['owner']['login']}/{repo['name']}/topics", + f"{config.instance_url}/api/v1/repos/{repo['owner']['login']}/{repo['name']}/topics", headers={"Authorization": f"token {config.token}"}, ).json()["topics"] repo["topics"] = topics