Add a new subcommand to trigger services

This commit is contained in:
Luca Beltrame 2022-01-23 22:28:47 +01:00
parent aca97152c7
commit e1a5879e41
Signed by: einar
GPG key ID: 4707F46E9EC72DEC

View file

@ -205,13 +205,37 @@ class OSCBot(Plugin):
await evt.reply(message, markdown=True)
@osc.subcommand(
"servicerun",
help="Trigger source services for a package")
@command.argument("project", "project name")
@command.argument("package", "package name")
async def servicerun(self, evt: MessageEvent,
project: str,
package: str) -> None:
token = self.config["trigger_token"]
trigger_url = f"{self.config['api_url']}/trigger/runservice"
params = {"project": project, "package": package}
header = {"Authorization": f"Token {token}"}
response = await self.http.post(trigger_url, params=params,
headers=header)
status = objectify.fromstring(await response.text())
if response.status == 200:
message = f"Service triggered: {status.summary.text}"
else:
message = f"Error running service: {status.summary.text}"
await evt.reply(message, markdown=True)
@osc.subcommand("status", aliases=("st",),
help="Check status for package and repository")
@command.argument("project", "project name")
@command.argument("package", "package name (optional)", required=False)
@command.argument("state", "build state (optional)", required=False)
@command.argument("repository", "repository (optional)", required=False)
@command.argument("arch", "architecture state (optional)", required=False)
@command.argument("package", "package name | all", required=False)
@command.argument("state", "build state | all", required=False)
@command.argument("repository", "repository | all)", required=False)
@command.argument("arch", "architecture state | all", required=False)
async def status(self, evt: MessageEvent,
project: str,
package: Optional[str] = None,