Browse Source

Improve modularity and re-apply formatting.

tags/v0.2^0
Evilham 1 year ago
parent
commit
95646e6f38
2 changed files with 50 additions and 13 deletions
  1. +34
    -7
      releasebot.py
  2. +16
    -6
      tests/test_releasebot.py

+ 34
- 7
releasebot.py View File

@@ -370,9 +370,6 @@ class ReleaseBot(object):
self.repo_store = repo_store

self.suites = _list_helper(config, "filters", "suites")
import itertools
self.restricted_suites = ['-'.join(i) for i in itertools.product(_list_helper(config, "filters", "restricted_suites"),
_list_helper(config, "filters", "restricted_suffixes"))]

def process(self):
for task in self.repo_store.get_pending_tasks():
@@ -391,18 +388,48 @@ class ReleaseBot(object):
else:
task.resolve_notify("You don't have permissions to run this task")
else:
task.resolve_notify('Command not supported: "{}". Available commands are: {}.'.format(task.command.name, ', '.join([x[4:] for x in dir(self) if x.startswith('cmd_')])))
task.resolve_notify(
'Command not supported: "{}". '
"Available commands are: {}.".format(
task.command.name, ", ".join(self.available_commands)
)
)
return task

@property
@functools.lru_cache()
def available_commands(self) -> typing.Iterable[str]:
"""
Return an exhaustive list of all supported commands in this class.
A command X is supported if a method is defined as follows:
cmd_X(self, task: ReleaseBotTask):
"""
return [x[4:] for x in dir(self) if x.startswith("cmd_")]

@property
@functools.lru_cache()
def restricted_suites(self) -> typing.Iterable[str]:
"""
Generate an exhaustive list of restricted suites.
Use the cartesian product of restricted_suites and restricted_suffixes.
"""
import itertools

filters = _list_helper(self.config, "filters", "restricted_suites")
suffixes = _list_helper(self.config, "filters", "restricted_suffixes")
return ["-".join(i) for i in itertools.product(filters, suffixes)]

def cmd_build(self, task: ReleaseBotTask):
if not task.command.labels:
task.resolve_notify("You must assign some labels")
return False

for suite in sorted(task.command.labels):
if suite not in self.suites+self.restricted_suites:
task.notify('Ignoring unrecognised tag or disallowed suite "{}"'.format(suite))
continue
if suite not in self.suites + self.restricted_suites:
task.notify(
'Ignoring unrecognised tag or disallowed suite "{}"'.format(suite)
)
continue
url = self.job_store.queue_build(suite, task.command.package)
task.notify(
'Triggered "{}" build for "{}": {}'.format(


+ 16
- 6
tests/test_releasebot.py View File

@@ -118,7 +118,9 @@ tested_open_issues = [
"assignee": {"username": "releasebot"},
"user": {"username": "toor", "is_admin": True},
"expected_messages": ["Triggered", "Finished queueing"],
"expected_builds": [{"codename": "beowulf-proposed-updates", "srcpackage": "stuff"}],
"expected_builds": [
{"codename": "beowulf-proposed-updates", "srcpackage": "stuff"}
],
},
{
"number": 28,
@@ -152,7 +154,7 @@ tested_open_issues = [
"expected_messages": ["Triggered", "Finished queueing"],
"expected_builds": [{"codename": "unstable", "srcpackage": "stuff"}],
},
{
{
"number": 31,
"title": "Build",
"descr": "Is 'pending', packages group member",
@@ -180,7 +182,9 @@ def expected_pending_tasks(repo_store):
return [
ReleaseBotTask(
id="devuan/stuff/issues/20",
command=ReleaseBotCommand(name="build", package="stuff", labels=set(["unstable"])),
command=ReleaseBotCommand(
name="build", package="stuff", labels=set(["unstable"])
),
requester=ReleaseBotRequester(name="koala", permissions=[]),
repo_store=repo_store,
),
@@ -249,7 +253,9 @@ def expected_pending_tasks(repo_store):
ReleaseBotTask(
id="devuan/stuff/issues/29",
command=ReleaseBotCommand(
name="build", package="stuff", labels=set(["private","beowulf-proposed"])
name="build",
package="stuff",
labels=set(["private", "beowulf-proposed"]),
),
requester=ReleaseBotRequester(name="toor", is_admin=True, permissions=[]),
repo_store=repo_store,
@@ -259,7 +265,9 @@ def expected_pending_tasks(repo_store):
command=ReleaseBotCommand(
name="build", package="stuff", labels=set(["unstable"])
),
requester=ReleaseBotRequester(name="colab", is_admin=False, permissions=['collaborator/stuff']),
requester=ReleaseBotRequester(
name="colab", is_admin=False, permissions=["collaborator/stuff"]
),
repo_store=repo_store,
),
ReleaseBotTask(
@@ -267,7 +275,9 @@ def expected_pending_tasks(repo_store):
command=ReleaseBotCommand(
name="build", package="stuff", labels=set(["experimental"])
),
requester=ReleaseBotRequester(name="dev1dev", is_admin=False, permissions=['member']),
requester=ReleaseBotRequester(
name="dev1dev", is_admin=False, permissions=["member"]
),
repo_store=repo_store,
),
ReleaseBotTask(


Loading…
Cancel
Save