Merge pull request #133 from Mic92/gitea-fixes

Gitea fixes
This commit is contained in:
Jörg Thalheim 2024-05-01 12:19:22 +02:00 committed by GitHub
commit f767c7ee37
Failed to generate hash of commit
3 changed files with 22 additions and 15 deletions

View file

@ -5,7 +5,8 @@ from collections.abc import Generator
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from typing import Any from typing import TYPE_CHECKING, Any
from urllib.parse import urlparse
from buildbot.config.builder import BuilderConfig from buildbot.config.builder import BuilderConfig
from buildbot.plugins import util from buildbot.plugins import util
@ -20,6 +21,9 @@ from twisted.internet import defer, threads
from twisted.python import log from twisted.python import log
from twisted.python.failure import Failure from twisted.python.failure import Failure
if TYPE_CHECKING:
from buildbot.process.log import StreamLog
from .common import ( from .common import (
http_request, http_request,
paginated_github_request, paginated_github_request,
@ -66,7 +70,7 @@ class GiteaProject(GitProject):
webhook_url: str, webhook_url: str,
) -> None: ) -> None:
hooks = paginated_github_request( 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(), self.config.token(),
) )
config = dict( config = dict(
@ -93,14 +97,15 @@ class GiteaProject(GitProject):
return return
http_request( 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", method="POST",
headers=headers, headers=headers,
data=data, data=data,
) )
def get_project_url(self) -> str: 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 @property
def pretty_type(self) -> str: def pretty_type(self) -> str:
@ -167,7 +172,7 @@ class GiteaBackend(GitBackend):
def create_reporter(self) -> ReporterBase: def create_reporter(self) -> ReporterBase:
return GiteaStatusPush( return GiteaStatusPush(
"https://" + self.config.instance_url, self.config.instance_url,
Interpolate(self.config.token()), Interpolate(self.config.token()),
context=Interpolate("buildbot/%(prop:status_name)s"), context=Interpolate("buildbot/%(prop:status_name)s"),
context_pr=Interpolate("buildbot/%(prop:status_name)s"), context_pr=Interpolate("buildbot/%(prop:status_name)s"),
@ -184,7 +189,7 @@ class GiteaBackend(GitBackend):
def create_auth(self) -> AuthBase: def create_auth(self) -> AuthBase:
assert self.config.oauth_id is not None, "Gitea requires an OAuth ID to be set" assert self.config.oauth_id is not None, "Gitea requires an OAuth ID to be set"
return GiteaAuth( return GiteaAuth(
"https://" + self.config.instance_url, self.config.instance_url,
self.config.oauth_id, self.config.oauth_id,
self.config.oauth_secret(), self.config.oauth_secret(),
) )
@ -259,9 +264,8 @@ class ReloadGiteaProjects(BuildStep):
os.kill(os.getpid(), signal.SIGHUP) os.kill(os.getpid(), signal.SIGHUP)
return util.SUCCESS return util.SUCCESS
else: else:
yield self.addLog("log").addStderr( log: StreamLog = yield self.addLog("log")
f"Failed to reload project list: {self.error_msg}" log.addStderr(f"Failed to reload project list: {self.error_msg}")
)
return util.FAILURE return util.FAILURE
@ -269,7 +273,7 @@ def refresh_projects(config: GiteaConfig, repo_cache_file: Path) -> None:
repos = [] repos = []
for repo in paginated_github_request( 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(), config.token(),
): ):
if not repo["permissions"]["admin"]: if not repo["permissions"]["admin"]:
@ -281,7 +285,7 @@ def refresh_projects(config: GiteaConfig, repo_cache_file: Path) -> None:
try: try:
# Gitea doesn't include topics in the default repo listing, unlike GitHub # Gitea doesn't include topics in the default repo listing, unlike GitHub
topics: list[str] = http_request( 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}"}, headers={"Authorization": f"token {config.token}"},
).json()["topics"] ).json()["topics"]
repo["topics"] = topics repo["topics"] = topics

View file

@ -5,7 +5,7 @@ from collections.abc import Generator
from dataclasses import dataclass from dataclasses import dataclass
from pathlib import Path from pathlib import Path
from tempfile import NamedTemporaryFile from tempfile import NamedTemporaryFile
from typing import Any from typing import TYPE_CHECKING, Any
from buildbot.config.builder import BuilderConfig from buildbot.config.builder import BuilderConfig
from buildbot.plugins import util from buildbot.plugins import util
@ -20,6 +20,9 @@ from twisted.internet import defer, threads
from twisted.python import log from twisted.python import log
from twisted.python.failure import Failure from twisted.python.failure import Failure
if TYPE_CHECKING:
from buildbot.process.log import StreamLog
from .common import ( from .common import (
http_request, http_request,
paginated_github_request, paginated_github_request,
@ -57,9 +60,8 @@ class ReloadGithubProjects(BuildStep):
os.kill(os.getpid(), signal.SIGHUP) os.kill(os.getpid(), signal.SIGHUP)
return util.SUCCESS return util.SUCCESS
else: else:
yield self.addLog("log").addStderr( log: StreamLog = yield self.addLog("log")
f"Failed to reload project list: {self.error_msg}" log.addStderr(f"Failed to reload project list: {self.error_msg}")
)
return util.FAILURE return util.FAILURE

View file

@ -49,6 +49,7 @@ def setup_worker(
numcpus = None numcpus = None
allow_shutdown = None allow_shutdown = None
print(f"Starting worker {workername}")
s = Worker( s = Worker(
None, None,
None, None,