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) # (C)
from dataclasses import dataclass from dataclasses import dataclass
from typing import Optional, List, Type from typing import Optional, List, Type, Tuple
import aiohttp import aiohttp
from lxml import objectify from lxml import objectify
@ -51,16 +51,10 @@ class BuildRepository:
class Config(BaseProxyConfig): class Config(BaseProxyConfig):
def do_update(self, helper: ConfigUpdateHelper) -> None: def do_update(self, helper: ConfigUpdateHelper) -> None:
if "api_url" not in self: helper.copy("api_url")
helper.base["api_url"] = "https://api.opensuse.org" helper.copy("instance_url")
else: helper.copy("rebuild_token")
helper.copy("api_url") helper.copy("trigger_token")
if "token" not in self:
helper.base["token"] = "CHANGEME"
else:
helper.copy("token")
helper.copy("username") helper.copy("username")
helper.copy("password") helper.copy("password")
@ -82,12 +76,31 @@ class OSCBot(Plugin):
return Config return Config
async def parse_rebuilpac( async def parse_rebuilpac(
self, self,
project: str, project: str,
package: Optional[str] = None, package: Optional[str] = None,
repo: Optional[str] = None, repo: Optional[str] = None,
arch: Optional[str] = None) -> None: arch: Optional[str] = None) -> Tuple[bool, str]:
pass
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( async def parse_status(
self, self,
@ -182,6 +195,16 @@ class OSCBot(Plugin):
if arch == "all": if arch == "all":
arch = None 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",), @osc.subcommand("status", aliases=("st",),
help="Check status for package and repository") help="Check status for package and repository")
@command.argument("project", "project name") @command.argument("project", "project name")
@ -218,11 +241,10 @@ class OSCBot(Plugin):
message = header.render(state=state) message = header.render(state=state)
await evt.reply(message, markdown=True) 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: for repository in response:
body = self.template.from_string(REPO_TEMPLATE) body = self.template.from_string(REPO_TEMPLATE)
message = body.render(repo=repository, project=project, message = body.render(repo=repository, project=project,
base_url=base_url) base_url=base_url)
await evt.respond(message, markdown=True) await evt.respond(message, markdown=True)