Properly implement rebuilding packages

This commit is contained in:
Luca Beltrame 2022-01-23 18:59:05 +01:00
parent 67b38450d7
commit aca97152c7
Signed by: einar
GPG key ID: 4707F46E9EC72DEC

View file

@ -1,7 +1,7 @@
# (C)
from dataclasses import dataclass
from typing import Optional, List, Type
from typing import Optional, List, Type, Tuple
import aiohttp
from lxml import objectify
@ -51,16 +51,10 @@ class BuildRepository:
class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None:
if "api_url" not in self:
helper.base["api_url"] = "https://api.opensuse.org"
else:
helper.copy("api_url")
if "token" not in self:
helper.base["token"] = "CHANGEME"
else:
helper.copy("token")
helper.copy("api_url")
helper.copy("instance_url")
helper.copy("rebuild_token")
helper.copy("trigger_token")
helper.copy("username")
helper.copy("password")
@ -82,12 +76,31 @@ class OSCBot(Plugin):
return Config
async def parse_rebuilpac(
self,
project: str,
package: Optional[str] = None,
repo: Optional[str] = None,
arch: Optional[str] = None) -> None:
pass
self,
project: str,
package: Optional[str] = None,
repo: Optional[str] = None,
arch: Optional[str] = None) -> Tuple[bool, str]:
trigger_url = f"{self.config['api_url']}/trigger/rebuild"
header = {"Authorization": f"Token {self.config['rebuild_token']}"}
params = {"project": project}
if package:
params["package"] = package
if repo:
params["repository"] = repo
if arch:
params["arch"] = arch
response = await self.http.post(trigger_url, params=params,
headers=header)
status = objectify.fromstring(await response.text())
if response.status == 200:
return (True, status.summary.text)
else:
return (False, status.summary.text)
async def parse_status(
self,
@ -182,6 +195,16 @@ class OSCBot(Plugin):
if arch == "all":
arch = None
result, status = await self.parse_rebuilpac(project, package,
repository,
arch)
if not result:
message = f"Error received from OBS: {status}"
else:
message = f"Rebuild triggered {status}"
await evt.reply(message, markdown=True)
@osc.subcommand("status", aliases=("st",),
help="Check status for package and repository")
@command.argument("project", "project name")
@ -218,11 +241,10 @@ class OSCBot(Plugin):
message = header.render(state=state)
await evt.reply(message, markdown=True)
base_url = "https://build.opensuse.org" # TODO: Configure this
base_url = self.config["instance_url"]
for repository in response:
body = self.template.from_string(REPO_TEMPLATE)
message = body.render(repo=repository, project=project,
base_url=base_url)
await evt.respond(message, markdown=True)