diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-10-26 16:33:09 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-10-26 16:33:09 -0400 |
commit | d5630beac386587b1c71f8b50cdefdc5a5094c91 (patch) | |
tree | d4f9096b1a1fea5136e301f37278660c970de8e2 | |
parent | c87806a67b7b0a6ccf352b176c28dc1ffbdae86d (diff) | |
download | bugspray-d5630beac386587b1c71f8b50cdefdc5a5094c91.tar.gz |
Abstract public-inbox searches in config
We may want to be able to reuse searches across multiple component
definitions, so abstract them into their own config hierarchy.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | bugspray/__init__.py | 13 | ||||
-rw-r--r-- | bugspray/parse.py | 35 | ||||
-rw-r--r-- | bugspray/pi2bz.py | 9 | ||||
-rw-r--r-- | default.config.toml | 16 |
5 files changed, 52 insertions, 23 deletions
@@ -3,7 +3,7 @@ *.pyo *.json *.pdf -test.log +*.log build/* dist/* MANIFEST diff --git a/bugspray/__init__.py b/bugspray/__init__.py index a2332bc..f29dd57 100644 --- a/bugspray/__init__.py +++ b/bugspray/__init__.py @@ -93,6 +93,19 @@ def get_msgid_link(msgid: str) -> str: return linkmask.format(msgid=urllib.parse.quote_plus(msgid, safe='@')) +def get_pi_search(title: str) -> dict: + config = get_config() + try: + pconf = config['publicinbox']['searches'][title] + except KeyError: + raise LookupError('No such publicinbox search: %s' % title) + if 'inherits' in pconf: + mconf = get_pi_search(pconf['inherits']) + mconf.update(pconf) + return mconf + return pconf + + def bz_rest(path: str, payload: Dict = None, params: Dict = None, method: str = 'GET') -> Dict: global REST_CACHE # We only cache GETs without any params diff --git a/bugspray/parse.py b/bugspray/parse.py index 729954d..c9fddfe 100644 --- a/bugspray/parse.py +++ b/bugspray/parse.py @@ -184,21 +184,28 @@ def process_rfc2822(msg: email.message.EmailMessage, product: str, component: st new_bug_notification(bid, cid, dry_run=dry_run) # Do we have any assign triggers? - assign_res = cconf.get('pi_assign_regexes') - if assign_res: - assignee = get_assignee(msg, assign_res) - if assignee: - # Is this person allowed to set assignees? - author = bugspray.msg_get_author(msg) - fromaddr = author[1] - if bugspray.bz_check_user_allowed(fromaddr, product, component): - if not dry_run: - bugspray.bz_assign_bug(bid, assignee) - else: - logger.debug('---DRY RUN---') - logger.debug('Would have assigned bid=%s to %s', bid, assignee) + pst = cconf.get('pi_search') + if not pst: + return + + pconf = bugspray.get_pi_search(pst) + assign_res = pconf.get('assign_regexes') + if not assign_res: + return + + assignee = get_assignee(msg, assign_res) + if assignee: + # Is this person allowed to set assignees? + author = bugspray.msg_get_author(msg) + fromaddr = author[1] + if bugspray.bz_check_user_allowed(fromaddr, product, component): + if not dry_run: + bugspray.bz_assign_bug(bid, assignee) else: - logger.debug('User %s is not allowed to set assignees', fromaddr) + logger.debug('---DRY RUN---') + logger.debug('Would have assigned bid=%s to %s', bid, assignee) + else: + logger.debug('User %s is not allowed to set assignees', fromaddr) def main(cmdargs: argparse.Namespace) -> None: diff --git a/bugspray/pi2bz.py b/bugspray/pi2bz.py index 2366847..d32e1e4 100644 --- a/bugspray/pi2bz.py +++ b/bugspray/pi2bz.py @@ -43,7 +43,10 @@ def update_component(product: str, component: str, dry_run: bool = False): logger.info('Running pi2bz for %s/%s, dry_run=%s', product, component, dry_run) cconf = bugspray.get_component_config(product, component) tracked = get_tracked_bug_msgids(product, component) - url = cconf.get('pi_url').rstrip('/') + pstitle = cconf.get('pi_search') + pconf = bugspray.get_pi_search(pstitle) + + url = pconf.get('url').rstrip('/') now = datetime.datetime.utcnow() try: last_check = bugspray.db_get_query_last_check(product, component) @@ -77,7 +80,7 @@ def update_component(product: str, component: str, dry_run: bool = False): updates.append(tmsg) # Now grab the latest query matches - query = cconf.get('pi_query') + query = pconf.get('query') if query: logger.info('Running query for %s/%s', product, component) if last_check: @@ -100,7 +103,7 @@ def update_component(product: str, component: str, dry_run: bool = False): logger.debug('author=%s not allowed, skipping msg %s', fromaddr, msg.get('Subject')) continue # Check fine trigger, if configured - trigger_res = cconf.get('pi_trigger_regexes', list()) + trigger_res = pconf.get('trigger_regexes', list()) if trigger_res: payload = bugspray.msg_get_payload(msg) found = False diff --git a/default.config.toml b/default.config.toml index 77e9e12..e9fa922 100644 --- a/default.config.toml +++ b/default.config.toml @@ -28,14 +28,20 @@ deny = [ 'text/html', 'application/*-signature' ] logfile = 'bugspray.log' loglevel = 'info' +[publicinbox.searches.'bugbot-generic'] +url = 'https://lore.kernel.org/all/' +query = '(nq:"bugbot on" OR nq:"bugbot assign")' +# These are always multiline, case-insensitive +trigger_regexes = ['^bugbot on\s*$', '^bugbot assign to \S+$'] +assign_regexes = ['^bugbot assign to (\S+)'] + +[publicinbox.searches.'linux-generic'] +inherits = 'bugbot-generic' + [components.'Linux'.'Kernel'] new_bug_send_notification = true -pi_query = '(nq:"bugbot on" OR nq:"bugbot assign")' +pi_search = 'linux-generic' pi_must_bz_groups = ['editbugs'] -pi_url = 'https://lore.kernel.org/all/' -# These are always multiline, case-insensitive -pi_trigger_regexes = ['^bugbot on\s*$', '^bugbot assign to \S+$'] -pi_assign_regexes = ['^bugbot assign to (\S+)'] bz_new_bugs_quicksearch = 'OPEN flag:bugbot+' bz_privacy_mode = true alwayscc = ['bugs@lists.linux.dev'] |