From 32876558aedb7ca192ea7b8973bba19d5ab3103f Mon Sep 17 00:00:00 2001 From: Luca Beltrame Date: Sun, 23 Jan 2022 11:30:54 +0100 Subject: [PATCH] First working version Only checks status for now. --- oscbot/__init__.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/oscbot/__init__.py b/oscbot/__init__.py index cba9ff5..27d4c40 100644 --- a/oscbot/__init__.py +++ b/oscbot/__init__.py @@ -70,7 +70,7 @@ class OSCBot(Plugin): async def parse_status( self, project: str, - package: Optional[str], + package: Optional[str] = None, state: Optional[str] = None, repo: Optional[str] = None, arch: Optional[str] = None) -> List[BuildRepository]: @@ -112,9 +112,9 @@ class OSCBot(Plugin): continue packages = list() - for state in child.status: - package_name = state.get("package") - package_status = state.get("code") + for status in child.status: + package_name = status.get("package") + package_status = status.get("code") if state and state != package_status: self.log.debug(f"Skipping {package_name}," @@ -124,6 +124,9 @@ class OSCBot(Plugin): result = BuildResult(name=package_name, status=package_status) packages.append(result) + if not packages: + continue + repository = BuildRepository(name=repository_name, arch=repo_arch, packages=packages) @@ -150,21 +153,23 @@ class OSCBot(Plugin): repository: Optional[str] = None, arch: Optional[str] = None) -> None: + if state == "all": + state = None + if package == "all": + package = None + response = await self.parse_status(project, package, state=state, repo=repository, arch=arch) if not response: - await evt.reply("No results returned.") + await evt.reply("No results found.") return header = self.template.from_string(HEADER_TEMPLATE) - message = template.render(state=state, results=response) - - self.log.error(sys.getsizeof(message)) - - try: - await evt.reply(message, markdown=True) - except Exception as exc: - self.log.error(exc) - await evt.reply("Error sending message") + message = header.render(state=state) + await evt.reply(message, markdown=True) + for repository in response: + body = self.template.from_string(REPO_TEMPLATE) + message = body.render(repo=repository) + await evt.respond(message, markdown=True)