From 0ecf33f8d404fc017c0d88e36895bc82a4951442 Mon Sep 17 00:00:00 2001 From: magic_rb Date: Wed, 24 Jul 2024 21:22:46 +0200 Subject: [PATCH] Reformat `gitea_projects.py`, `__init__.py`, and `github_projects.py` Signed-off-by: magic_rb --- buildbot_nix/__init__.py | 5 +++-- buildbot_nix/common.py | 1 - buildbot_nix/gitea_projects.py | 18 ++++++++++++++---- buildbot_nix/github_projects.py | 20 +++++++++++++++----- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/buildbot_nix/__init__.py b/buildbot_nix/__init__.py index a4527f0..932708b 100644 --- a/buildbot_nix/__init__.py +++ b/buildbot_nix/__init__.py @@ -533,7 +533,7 @@ def nix_build_config( updateSourceStamp=False, doStepIf=do_register_gcroot_if, copy_properties=["out_path", "attr"], - set_properties={"report_status": False} + set_properties={"report_status": False}, ), ) factory.addStep( @@ -598,7 +598,7 @@ def nix_skipped_build_config( updateSourceStamp=False, doStepIf=do_register_gcroot_if, copy_properties=["out_path", "attr"], - set_properties={"report_status": False} + set_properties={"report_status": False}, ), ) return util.BuilderConfig( @@ -643,6 +643,7 @@ def nix_register_gcroot_config( factory=factory, ) + def nix_build_combined_config( project: GitProject, worker_names: list[str], diff --git a/buildbot_nix/common.py b/buildbot_nix/common.py index ed0a29d..c2d0ee2 100644 --- a/buildbot_nix/common.py +++ b/buildbot_nix/common.py @@ -180,4 +180,3 @@ def filter_for_combined_builds(reports: Any) -> Any | None: if "report_status" in properties and not properties["report_status"][0]: return None return reports - diff --git a/buildbot_nix/gitea_projects.py b/buildbot_nix/gitea_projects.py index 1282b26..24d6091 100644 --- a/buildbot_nix/gitea_projects.py +++ b/buildbot_nix/gitea_projects.py @@ -1,7 +1,8 @@ import os import signal +from collections.abc import Callable from pathlib import Path -from typing import Any, Callable +from typing import Any from urllib.parse import urlparse from buildbot.config.builder import BuilderConfig @@ -13,9 +14,9 @@ from buildbot.www.avatar import AvatarBase from buildbot_gitea.auth import GiteaAuth # type: ignore[import] from buildbot_gitea.reporter import GiteaStatusPush # type: ignore[import] from pydantic import BaseModel +from twisted.internet import defer from twisted.logger import Logger from twisted.python import log -from twisted.internet import defer from .common import ( ThreadDeferredBuildStep, @@ -106,13 +107,22 @@ class GiteaProject(GitProject): # TODO Gitea doesn't include this information return False # self.data["owner"]["type"] == "Organization" + class ModifyingGiteaStatusPush(GiteaStatusPush): - def checkConfig(self, modifyingFilter: Callable[[Any], Any | None] = lambda x: x, **kwargs: Any) -> Any: + def checkConfig( + self, + modifyingFilter: Callable[[Any], Any | None] = lambda x: x, # noqa: N803 + **kwargs: Any, + ) -> Any: self.modifyingFilter = modifyingFilter return super().checkConfig(**kwargs) - def reconfigService(self, modifyingFilter: Callable[[Any], Any | None] = lambda x: x, **kwargs: Any) -> Any: + def reconfigService( + self, + modifyingFilter: Callable[[Any], Any | None] = lambda x: x, # noqa: N803 + **kwargs: Any, + ) -> Any: self.modifyingFilter = modifyingFilter return super().reconfigService(**kwargs) diff --git a/buildbot_nix/github_projects.py b/buildbot_nix/github_projects.py index 35d5fe5..0b02b16 100644 --- a/buildbot_nix/github_projects.py +++ b/buildbot_nix/github_projects.py @@ -2,10 +2,11 @@ import json import os import signal from abc import ABC, abstractmethod +from collections.abc import Callable from dataclasses import dataclass from itertools import starmap from pathlib import Path -from typing import Any, Callable +from typing import Any from buildbot.config.builder import BuilderConfig from buildbot.plugins import util @@ -18,9 +19,9 @@ from buildbot.www.auth import AuthBase from buildbot.www.avatar import AvatarBase, AvatarGitHub from buildbot.www.oauth2 import GitHubAuth from pydantic import BaseModel, ConfigDict, Field +from twisted.internet import defer from twisted.logger import Logger from twisted.python import log -from twisted.internet import defer from .common import ( ThreadDeferredBuildStep, @@ -311,13 +312,22 @@ class GithubAuthBackend(ABC): ) -> list[BuildStep]: pass + class ModifyingGitHubStatusPush(GitHubStatusPush): - def checkConfig(self, modifyingFilter: Callable[[Any], Any | None] = lambda x: x, **kwargs: Any) -> Any: + def checkConfig( + self, + modifyingFilter: Callable[[Any], Any | None] = lambda x: x, # noqa: N803 + **kwargs: Any, + ) -> Any: self.modifyingFilter = modifyingFilter return super().checkConfig(**kwargs) - def reconfigService(self, modifyingFilter: Callable[[Any], Any | None] = lambda x: x, **kwargs: Any) -> Any: + def reconfigService( + self, + modifyingFilter: Callable[[Any], Any | None] = lambda x: x, # noqa: N803 + **kwargs: Any, + ) -> Any: self.modifyingFilter = modifyingFilter return super().reconfigService(**kwargs) @@ -331,6 +341,7 @@ class ModifyingGitHubStatusPush(GitHubStatusPush): result = yield super().sendMessage(reports) return result + class GithubLegacyAuthBackend(GithubAuthBackend): auth_type: GitHubLegacyConfig @@ -438,7 +449,6 @@ class GithubAppAuthBackend(GithubAuthBackend): self.project_id_map[props["projectname"]] ].get() - return ModifyingGitHubStatusPush( token=WithProperties("%(github_token)s", github_token=get_github_token), # Since we dynamically create build steps,