diff options
author | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-10-26 15:56:24 -0400 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2023-10-26 15:56:24 -0400 |
commit | c87806a67b7b0a6ccf352b176c28dc1ffbdae86d (patch) | |
tree | 0856da434ae2d7ce5113356c8b7903b3b6a82329 | |
parent | a31a92ff18a0df3b776a2a96d54a87bed65a23de (diff) | |
download | bugspray-c87806a67b7b0a6ccf352b176c28dc1ffbdae86d.tar.gz |
Rename peebz into bugspray
We will do more than just bugzilla, so don't tie ourselves to "bz" and
rename the project as "bugspray".
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rwxr-xr-x | bugspray.sh (renamed from peebz.sh) | 2 | ||||
-rw-r--r-- | bugspray/__init__.py (renamed from peebz/__init__.py) | 2 | ||||
-rw-r--r-- | bugspray/bz2pi.py (renamed from peebz/bz2pi.py) | 42 | ||||
-rw-r--r-- | bugspray/command.py (renamed from peebz/command.py) | 44 | ||||
-rw-r--r-- | bugspray/git2bz.py (renamed from peebz/git2bz.py) | 30 | ||||
-rw-r--r-- | bugspray/parse.py (renamed from peebz/parse.py) | 82 | ||||
-rw-r--r-- | bugspray/pi2bz.py (renamed from peebz/pi2bz.py) | 42 | ||||
-rw-r--r-- | default.config.toml | 4 | ||||
-rw-r--r-- | pyproject.toml | 12 | ||||
-rw-r--r-- | requirements.txt | 8 |
10 files changed, 134 insertions, 134 deletions
@@ -6,4 +6,4 @@ REAL_SCRIPT=$(realpath -e ${BASH_SOURCE[0]}) SCRIPT_TOP="${SCRIPT_TOP:-$(dirname ${REAL_SCRIPT})}" -exec env PYTHONPATH="${SCRIPT_TOP}" python3 "${SCRIPT_TOP}/peebz/command.py" "${@}" +exec env PYTHONPATH="${SCRIPT_TOP}" python3 "${SCRIPT_TOP}/bugspray/command.py" "${@}" diff --git a/peebz/__init__.py b/bugspray/__init__.py index 2574d44..a2332bc 100644 --- a/peebz/__init__.py +++ b/bugspray/__init__.py @@ -32,7 +32,7 @@ b4.emlpolicy = emlpolicy REQSESSION = None CONFIG = dict() -__APPNAME__ = 'peebz' +__APPNAME__ = 'bugspray' __VERSION__ = '0.1' __DBSCHEMA__ = 1 diff --git a/peebz/bz2pi.py b/bugspray/bz2pi.py index 77eea1f..f9806a8 100644 --- a/peebz/bz2pi.py +++ b/bugspray/bz2pi.py @@ -4,7 +4,7 @@ # Copyright (C) 2023 by the Linux Foundation import argparse -import peebz +import bugspray import datetime import time import re @@ -15,18 +15,18 @@ import email.utils from fnmatch import fnmatch -logger = peebz.logger +logger = bugspray.logger def process_new_comments(bid: int, privacy_mode: bool = False, dry_run: bool = False): - config = peebz.get_config() - cdatas = peebz.bz_get_newest_comments_for_bid(bid) + config = bugspray.get_config() + cdatas = bugspray.bz_get_newest_comments_for_bid(bid) msgts = int(time.time()) for cdata in cdatas: # Check if we've already notified about this bug cid = cdata['id'] try: - peebz.db_get_msgid_by_bid_cid(bid, cid) + bugspray.db_get_msgid_by_bid_cid(bid, cid) logger.debug('Skipping, msgid match for bid=%s, cid=%s', bid, cid) continue except LookupError: @@ -63,27 +63,27 @@ def process_new_comments(bid: int, privacy_mode: bool = False, dry_run: bool = F } if cdata['attachment_id']: logger.info('Processing new attachment for bug_id=%s, comment_id=%s', bid, cid) - adata = peebz.bz_get_attachment_by_aid( + adata = bugspray.bz_get_attachment_by_aid( cdata['attachment_id'], include_fields='file_name,size,content_type,summary,is_patch,is_private', ) if adata['is_private']: logger.debug('Skipping attachment marked private') continue - bodytpt = peebz.get_template_by_bid('new_attachment_notify', bid) + bodytpt = bugspray.get_template_by_bid('new_attachment_notify', bid) bodyvals.update(adata) bodyvals['attachment_url'] = config['bugzilla'].get('attachmask', '').format( attachment_id=cdata['attachment_id']) else: logger.info('Processing new comment for bug_id=%s, comment_id=%s', bid, cid) - bodytpt = peebz.get_template_by_bid('new_comment_notify', bid) + bodytpt = bugspray.get_template_by_bid('new_comment_notify', bid) fline = clines[0] matches = re.search(r'\(In reply to.*from comment #(\d+)', fline, flags=re.I) if matches: inre_count = int(matches.groups()[0]) try: - inre_cid = peebz.bz_get_cid_by_bid_count(bid, inre_count) + inre_cid = bugspray.bz_get_cid_by_bid_count(bid, inre_count) except LookupError: pass bodyvals['comment_text'] = '\n'.join(clines) @@ -97,16 +97,16 @@ def process_new_comments(bid: int, privacy_mode: bool = False, dry_run: bool = F except ValueError: pass body = bodytpt.safe_substitute(bodyvals) - body = peebz.add_bot_signature(body) + body = bugspray.add_bot_signature(body) msg.set_payload(body, charset='utf-8') - msgid = peebz.notify_bug(bid, cid, msg, inre_cid=inre_cid, dry_run=dry_run) + msgid = bugspray.notify_bug(bid, cid, msg, inre_cid=inre_cid, dry_run=dry_run) if msgid and not dry_run: - peebz.db_store_msgid_bid_cid(msgid, bid, cid) + bugspray.db_store_msgid_bid_cid(msgid, bid, cid) if not privacy_mode: - peebz.db_store_recipients(bid, {cdata['creator']}) + bugspray.db_store_recipients(bid, {cdata['creator']}) # TODO: This assumes that comments are always in incremental order lastcheck = cdata['creation_time'].replace('T', ' ').rstrip('Z') - peebz.db_store_notify_last_check(bid, lastcheck) + bugspray.db_store_notify_last_check(bid, lastcheck) def main(cmdargs: argparse.Namespace) -> None: @@ -114,7 +114,7 @@ def main(cmdargs: argparse.Namespace) -> None: lastrun = now.strftime('%Y-%m-%d %H:%M:%S') try: # Get all new bugs that changed since last run - since = peebz.db_get_meta_value('notify_last_run') + since = bugspray.db_get_meta_value('notify_last_run') except LookupError: logger.debug('Got a LookupError, getting everything for the past hour') # Assume it's the first run and get changes for the past hour @@ -123,14 +123,14 @@ def main(cmdargs: argparse.Namespace) -> None: # first, process all changed bugs that we're tracking logger.info('Getting a list of changed bugs since %s', since) - buglist = peebz.bz_get_changed_bugs(since) + buglist = bugspray.bz_get_changed_bugs(since) seen = set() - config = peebz.get_config() + config = bugspray.get_config() if buglist: for bdata in buglist: logger.debug('Looking at %s: %s', bdata['id'], bdata['summary']) bid = bdata['id'] - privacy_mode = peebz.get_privacy_mode(bdata['product'], bdata['component']) + privacy_mode = bugspray.get_privacy_mode(bdata['product'], bdata['component']) process_new_comments(bid, privacy_mode=privacy_mode, dry_run=cmdargs.dry_run) seen.add(bid) else: @@ -139,7 +139,7 @@ def main(cmdargs: argparse.Namespace) -> None: # Now go by product/component and handle new bug queries if defined for bz_product, bz_components in config['components'].items(): for bz_component in bz_components.keys(): - cconf = peebz.get_component_config(bz_product, bz_component) + cconf = bugspray.get_component_config(bz_product, bz_component) qs = cconf.get('bz_new_bugs_quicksearch') if not qs: logger.debug('No quicksearch defined for %s/%s', bz_product, bz_component) @@ -152,7 +152,7 @@ def main(cmdargs: argparse.Namespace) -> None: 'component': bz_component, 'quicksearch': qs, } - buglist = peebz.bz_get_query_bugs(params, exclude=seen) + buglist = bugspray.bz_get_query_bugs(params, exclude=seen) if config['bugzilla'].get('privacy_mode', False) or cconf.get('bz_privacy_mode', False): privacy_mode = True else: @@ -166,4 +166,4 @@ def main(cmdargs: argparse.Namespace) -> None: logger.info('No changed bugs matching these parameters.') if not cmdargs.dry_run: - peebz.db_store_meta_value(key='notify_last_run', value=lastrun) + bugspray.db_store_meta_value(key='notify_last_run', value=lastrun) diff --git a/peebz/command.py b/bugspray/command.py index 7b6dc16..24e6d8a 100644 --- a/peebz/command.py +++ b/bugspray/command.py @@ -11,29 +11,29 @@ import time import b4 import logging import logging.handlers -import peebz +import bugspray -logger = peebz.logger +logger = bugspray.logger def cmd_parse(cmdargs): - import peebz.parse - peebz.parse.main(cmdargs) + import bugspray.parse + bugspray.parse.main(cmdargs) def cmd_bz2pi(cmdargs): - import peebz.bz2pi - peebz.bz2pi.main(cmdargs) + import bugspray.bz2pi + bugspray.bz2pi.main(cmdargs) def cmd_pi2bz(cmdargs): - import peebz.pi2bz - peebz.pi2bz.main(cmdargs) + import bugspray.pi2bz + bugspray.pi2bz.main(cmdargs) def cmd_git2bz(cmdargs): - import peebz.git2bz - peebz.git2bz.main(cmdargs) + import bugspray.git2bz + bugspray.git2bz.main(cmdargs) def cmd_cron(cmdargs): @@ -53,13 +53,13 @@ def cmd_bzdump(cmdargs): import json from pygments import highlight, lexers, formatters if cmdargs.bug_id: - rdata = peebz.bz_get_bug(cmdargs.bug_id, resolve_dupes=cmdargs.resolve_dupes) + rdata = bugspray.bz_get_bug(cmdargs.bug_id, resolve_dupes=cmdargs.resolve_dupes) elif cmdargs.username: - rdata = peebz.bz_get_user(cmdargs.username) + rdata = bugspray.bz_get_user(cmdargs.username) elif cmdargs.quicksearch: - rdata = peebz.bz_quicksearch_bugs(query=cmdargs.quicksearch) + rdata = bugspray.bz_quicksearch_bugs(query=cmdargs.quicksearch) elif cmdargs.attachment_id: - rdata = peebz.bz_get_attachment_by_aid(int(cmdargs.attachment_id)) + rdata = bugspray.bz_get_attachment_by_aid(int(cmdargs.attachment_id)) else: sys.exit(1) @@ -71,11 +71,11 @@ def cmd_bzdump(cmdargs): def setup_parser() -> argparse.ArgumentParser: # noinspection PyTypeChecker parser = argparse.ArgumentParser( - prog='peebz', + prog='bugspray', description='A tool to bridge public-inbox collections with bugzilla', formatter_class=argparse.ArgumentDefaultsHelpFormatter, ) - parser.add_argument('--version', action='version', version=peebz.__VERSION__) + parser.add_argument('--version', action='version', version=bugspray.__VERSION__) parser.add_argument('-d', '--debug', action='store_true', default=False, help='Add more debugging info to the output') parser.add_argument('-q', '--quiet', action='store_true', default=False, @@ -150,17 +150,17 @@ def cmd(): with open(cmdargs.config, 'rb') as fh: try: import tomllib # noqa - peebz.CONFIG = tomllib.load(fh) + bugspray.CONFIG = tomllib.load(fh) except ModuleNotFoundError: import tomli # noqa - peebz.CONFIG = tomli.load(fh) + bugspray.CONFIG = tomli.load(fh) try: - logfile = peebz.CONFIG['logging']['logfile'] + logfile = bugspray.CONFIG['logging']['logfile'] flh = logging.handlers.WatchedFileHandler(logfile) fmt = '[%(process)d] %(asctime)s - ' + cmdargs.subcmd + ': %(message)s' flh.setFormatter(logging.Formatter(fmt)) - loglevel = peebz.CONFIG['logging'].get('loglevel', 'info') + loglevel = bugspray.CONFIG['logging'].get('loglevel', 'info') if loglevel == 'debug': flh.setLevel(logging.DEBUG) else: @@ -177,12 +177,12 @@ if __name__ == '__main__': import os # noinspection PyBroadException try: - if peebz.__VERSION__.endswith('-dev'): + if bugspray.__VERSION__.endswith('-dev'): base = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) dotgit = os.path.join(base, '.git') lines = b4.git_get_command_lines(dotgit, ['rev-parse', '--short', 'HEAD']) if lines: - peebz.__VERSION__ = '%s-%.5s' % (peebz.__VERSION__, lines[0].strip()) + bugspray.__VERSION__ = '%s-%.5s' % (bugspray.__VERSION__, lines[0].strip()) except Exception as ex: pass cmd() diff --git a/peebz/git2bz.py b/bugspray/git2bz.py index 935a19b..d739298 100644 --- a/peebz/git2bz.py +++ b/bugspray/git2bz.py @@ -4,25 +4,25 @@ # Copyright (C) 2023 by the Linux Foundation import argparse -import peebz -import peebz.parse +import bugspray +import bugspray.parse import b4 import email.message import re -logger = peebz.logger +logger = bugspray.logger b4.logger = logger # force b4 to use EmailMessage factory -b4.emlpolicy = peebz.emlpolicy +b4.emlpolicy = bugspray.emlpolicy def update_component(product: str, component: str, dry_run: bool = False): logger.info('Running git2bz for %s/%s, dry_run=%s', product, component, dry_run) - cconf = peebz.get_component_config(product, component) + cconf = bugspray.get_component_config(product, component) cres = cconf.get('git_log_closes_regexes', list()) mres = cconf.get('git_log_mentions_regexes', list()) since = cconf.get('git_log_since', '1.week') - tpt = peebz.get_template_by_product_component('new_commit_notify', product, component) + tpt = bugspray.get_template_by_product_component('new_commit_notify', product, component) for entry in cconf.get('git_repos', list()): repo = entry[0] try: @@ -45,7 +45,7 @@ def update_component(product: str, component: str, dry_run: bool = False): logger.debug(' query returned %s commits', len(lines)) for line in lines: csha = line.split(maxsplit=1)[0] - known_bids = peebz.db_get_bugs_for_commit(csha) + known_bids = bugspray.db_get_bugs_for_commit(csha) if len(known_bids): logger.debug('This commit already processed, bugs: %s', known_bids) continue @@ -97,26 +97,26 @@ def update_component(product: str, component: str, dry_run: bool = False): desc = tpt.safe_substitute(vals) msg = email.message.EmailMessage() - body = peebz.add_bot_signature(desc) + body = bugspray.add_bot_signature(desc) msg.set_payload(body, charset='utf-8') if not dry_run: - cid = peebz.bz_add_new_comment(bid, desc) - msgid = peebz.notify_bug(bid, cid, msg, dry_run=dry_run) + cid = bugspray.bz_add_new_comment(bid, desc) + msgid = bugspray.notify_bug(bid, cid, msg, dry_run=dry_run) if msgid: - peebz.db_store_msgid_bid_cid(msgid, bid, cid) - peebz.db_store_bug_for_commit(csha, bid) + bugspray.db_store_msgid_bid_cid(msgid, bid, cid) + bugspray.db_store_bug_for_commit(csha, bid) if closes: status, resolution = cconf.get('git_closes_with', ['RESOLVED', 'FIXED']) logger.info('Commit %s closes bug %s with %s/%s', csha, bid, status, resolution) - peebz.bz_set_bug_status_resolution(bid, status, resolution) + bugspray.bz_set_bug_status_resolution(bid, status, resolution) else: logger.info('Commit %s mentions bug %s', csha, bid) else: - peebz.notify_bug(bid, None, msg, dry_run=dry_run) + bugspray.notify_bug(bid, None, msg, dry_run=dry_run) def main(cmdargs: argparse.Namespace): - config = peebz.get_config() + config = bugspray.get_config() # Iterate all components for bz_product, bz_components in config['components'].items(): for bz_component in bz_components.keys(): diff --git a/peebz/parse.py b/bugspray/parse.py index f6785cc..729954d 100644 --- a/peebz/parse.py +++ b/bugspray/parse.py @@ -5,7 +5,7 @@ import sys import argparse -import peebz +import bugspray import b4 import re @@ -14,35 +14,35 @@ from typing import Tuple, Dict, List import email.message import email.utils -logger = peebz.logger +logger = bugspray.logger def new_bug_notification(bid: int, inre_cid: int, dry_run: bool = False): msg = email.message.EmailMessage() - config = peebz.get_config() + config = bugspray.get_config() bodyvals = { 'bzname': config['bugzilla'].get('name'), 'bug_url': config['bugzilla'].get('bugmask', '').format(bug_id=bid), } - bodytpt = peebz.get_template_by_bid('new_bug_notify', bid) + bodytpt = bugspray.get_template_by_bid('new_bug_notify', bid) body = bodytpt.safe_substitute(bodyvals) - sigtpt = peebz.get_template_by_bid('botsig', bid) + sigtpt = bugspray.get_template_by_bid('botsig', bid) sigvals = { 'myname': config['bugzilla'].get('name'), - 'appname': peebz.__APPNAME__, - 'appver': peebz.__VERSION__, + 'appname': bugspray.__APPNAME__, + 'appver': bugspray.__VERSION__, } body += sigtpt.safe_substitute(sigvals) msg.set_payload(body, charset='utf-8') - peebz.notify_bug(bid, None, msg, inre_cid=inre_cid, dry_run=dry_run) + bugspray.notify_bug(bid, None, msg, inre_cid=inre_cid, dry_run=dry_run) def make_bug_desc_from_body(product: str, component: str, body: str, vals: Dict) -> str: if 'comment_count' in vals and vals['comment_count']: - tpt_intro = peebz.get_template_by_product_component('parse_bug_intro_with_count', product, component) + tpt_intro = bugspray.get_template_by_product_component('parse_bug_intro_with_count', product, component) else: - tpt_intro = peebz.get_template_by_product_component('parse_bug_intro', product, component) - tpt_outro = peebz.get_template_by_product_component('parse_bug_outro', product, component) + tpt_intro = bugspray.get_template_by_product_component('parse_bug_intro', product, component) + tpt_outro = bugspray.get_template_by_product_component('parse_bug_outro', product, component) desc = '' intro = tpt_intro.safe_substitute(vals) if intro: @@ -58,24 +58,24 @@ def make_bug_desc_from_body(product: str, component: str, body: str, vals: Dict) def new_bug_from_msg(msg: email.message.EmailMessage, product: str, component: str, dry_run: bool = False) -> Tuple[int, int]: - msgid, author, subject, body, atts = peebz.msg_parse_for_bug(msg) - payload = peebz.get_newbug_payload_by_product_component(product, component) + msgid, author, subject, body, atts = bugspray.msg_parse_for_bug(msg) + payload = bugspray.get_newbug_payload_by_product_component(product, component) summary = re.sub(r'^\s*(Re|Fwd):\s*', '', subject) vals = { 'author': b4.format_addrs([author]), - 'msgid_link': peebz.get_msgid_link(msgid), + 'msgid_link': bugspray.get_msgid_link(msgid), } desc = make_bug_desc_from_body(product, component, body, vals) payload['summary'] = summary payload['description'] = desc if not dry_run: - bid, cid = peebz.bz_add_new_bug(payload) + bid, cid = bugspray.bz_add_new_bug(payload) logger.debug('new bug bid=%s, cid=%s', bid, cid) - recipients = peebz.msg_get_recipients(msg) - peebz.db_store_recipients(bid, recipients) + recipients = bugspray.msg_get_recipients(msg) + bugspray.db_store_recipients(bid, recipients) if atts: - peebz.bz_add_atts_to_bug(bid, atts) + bugspray.bz_add_atts_to_bug(bid, atts) else: logger.info('--- DRY RUN ---') logger.info('Would have created a new bug in %s/%s:', product, component) @@ -88,26 +88,26 @@ def new_bug_from_msg(msg: email.message.EmailMessage, product: str, component: s def new_comment_from_msg(bid: int, cid: int, msg: email.message.EmailMessage, dry_run: bool = False) -> int: - msgid, author, subject, body, atts = peebz.msg_parse_for_bug(msg) + msgid, author, subject, body, atts = bugspray.msg_parse_for_bug(msg) vals = { 'author': b4.format_addrs([author]), - 'msgid_link': peebz.get_msgid_link(msgid), + 'msgid_link': bugspray.get_msgid_link(msgid), } if cid: try: - vals['comment_count'] = peebz.bz_get_count_by_bid_cid(bid, cid) + vals['comment_count'] = bugspray.bz_get_count_by_bid_cid(bid, cid) except LookupError: pass - product, component = peebz.bz_get_product_component_by_bid(bid) + product, component = bugspray.bz_get_product_component_by_bid(bid) desc = make_bug_desc_from_body(product, component, body, vals) if not dry_run: - cid = peebz.bz_add_new_comment(bid, desc) - recipients = peebz.msg_get_recipients(msg) - peebz.db_store_recipients(bid, recipients) + cid = bugspray.bz_add_new_comment(bid, desc) + recipients = bugspray.msg_get_recipients(msg) + bugspray.db_store_recipients(bid, recipients) if atts: - peebz.bz_add_atts_to_bug(bid, atts) + bugspray.bz_add_atts_to_bug(bid, atts) else: logger.info('--- DRY RUN ---') logger.info('Would have added this comment to %s', bid) @@ -117,8 +117,8 @@ def new_comment_from_msg(bid: int, cid: int, msg: email.message.EmailMessage, dr def get_assignee(msg: email.message.EmailMessage, regexes: List[str]) -> str: - payload = peebz.msg_get_payload(msg) - fromaddr = peebz.msg_get_author(msg)[1] + payload = bugspray.msg_get_payload(msg) + fromaddr = bugspray.msg_get_author(msg)[1] assignee = None for regex in regexes: @@ -130,7 +130,7 @@ def get_assignee(msg: email.message.EmailMessage, regexes: List[str]) -> str: assignee = fromaddr # Does this user exist? try: - peebz.bz_get_user(assignee) + bugspray.bz_get_user(assignee) logger.debug('found assignee=%s (matched regex: %s)', assignee, regex) # First match wins break @@ -149,12 +149,12 @@ def process_rfc2822(msg: email.message.EmailMessage, product: str, component: st logger.debug('Skipping bugzilla-originating message') return - cconf = peebz.get_component_config(product, component) + cconf = bugspray.get_component_config(product, component) # Get the message-id msgid = b4.LoreMessage.get_clean_msgid(msg) try: # If we have this exact msgid, then it's a dupe - bid, cid = peebz.db_get_bid_cid_by_msgid(msgid) + bid, cid = bugspray.db_get_bid_cid_by_msgid(msgid) logger.info('Already recorded as bid=%s, cid=%s', bid, cid) return except LookupError: @@ -163,23 +163,23 @@ def process_rfc2822(msg: email.message.EmailMessage, product: str, component: st # Walk through references and in-reply-to and see if we know any of them bid = cid = None try: - bid, cid = peebz.msg_get_inre_bid_cid(msg) + bid, cid = bugspray.msg_get_inre_bid_cid(msg) except LookupError: pass if bid: - bdata = peebz.bz_get_bug(bid) + bdata = bugspray.bz_get_bug(bid) if not bdata['is_open']: logger.info('Bug %s is closed, not adding comments', bid) sys.exit(0) cid = new_comment_from_msg(bid, cid, msg, dry_run=dry_run) if not dry_run: - peebz.db_store_msgid_bid_cid(msgid, bid, cid) + bugspray.db_store_msgid_bid_cid(msgid, bid, cid) else: bid, cid = new_bug_from_msg(msg, product, component, dry_run=dry_run) if not dry_run: - peebz.db_store_msgid_bid_cid(msgid, bid, cid) + bugspray.db_store_msgid_bid_cid(msgid, bid, cid) if cconf.get('new_bug_send_notification'): new_bug_notification(bid, cid, dry_run=dry_run) @@ -189,11 +189,11 @@ def process_rfc2822(msg: email.message.EmailMessage, product: str, component: st assignee = get_assignee(msg, assign_res) if assignee: # Is this person allowed to set assignees? - author = peebz.msg_get_author(msg) + author = bugspray.msg_get_author(msg) fromaddr = author[1] - if peebz.bz_check_user_allowed(fromaddr, product, component): + if bugspray.bz_check_user_allowed(fromaddr, product, component): if not dry_run: - peebz.bz_assign_bug(bid, assignee) + bugspray.bz_assign_bug(bid, assignee) else: logger.debug('---DRY RUN---') logger.debug('Would have assigned bid=%s to %s', bid, assignee) @@ -202,13 +202,13 @@ def process_rfc2822(msg: email.message.EmailMessage, product: str, component: st def main(cmdargs: argparse.Namespace) -> None: - msg = peebz.get_msg_from_stdin() + msg = bugspray.get_msg_from_stdin() product = cmdargs.product component = cmdargs.component if not (product and component): - recipients = peebz.msg_get_recipients(msg) + recipients = bugspray.msg_get_recipients(msg) try: - product, component = peebz.get_product_component_by_recipients(recipients) + product, component = bugspray.get_product_component_by_recipients(recipients) except LookupError as ex: # TODO: fail properly here logger.info(str(ex)) diff --git a/peebz/pi2bz.py b/bugspray/pi2bz.py index e511d56..2366847 100644 --- a/peebz/pi2bz.py +++ b/bugspray/pi2bz.py @@ -4,19 +4,19 @@ # Copyright (C) 2023 by the Linux Foundation import argparse -import peebz -import peebz.parse +import bugspray +import bugspray.parse import urllib.parse import datetime import re from typing import Set -logger = peebz.logger +logger = bugspray.logger def get_tracked_bug_msgids(product: str, component: str) -> Set[str]: - cconf = peebz.get_component_config(product, component) + cconf = bugspray.get_component_config(product, component) params = { 'include_fields': 'id', 'product': product, @@ -25,12 +25,12 @@ def get_tracked_bug_msgids(product: str, component: str) -> Set[str]: 'chfieldfrom': '90d', } params.update(cconf.get('bz_query_params', dict())) - rdata = peebz.bz_rest('bug', params=params) + rdata = bugspray.bz_rest('bug', params=params) msgids = set() for bdata in rdata.get('bugs', list()): bid = bdata['id'] try: - msgid = peebz.db_get_msgid_by_bid_cid(bid, None) + msgid = bugspray.db_get_msgid_by_bid_cid(bid, None) logger.debug('bid=%s is tracked as msgid=%s', bid, msgid) msgids.add(msgid) except LookupError: @@ -41,12 +41,12 @@ def get_tracked_bug_msgids(product: str, component: str) -> Set[str]: 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 = peebz.get_component_config(product, component) + cconf = bugspray.get_component_config(product, component) tracked = get_tracked_bug_msgids(product, component) url = cconf.get('pi_url').rstrip('/') now = datetime.datetime.utcnow() try: - last_check = peebz.db_get_query_last_check(product, component) + last_check = bugspray.db_get_query_last_check(product, component) except LookupError: last_check = None @@ -56,20 +56,20 @@ def update_component(product: str, component: str, dry_run: bool = False): logger.info('Checking for updates in %s tracked threads', len(tracked)) for msgid in tracked: try: - tmsgs = peebz.pi_get_sorted_thread(url, msgid, since=last_check) + tmsgs = bugspray.pi_get_sorted_thread(url, msgid, since=last_check) logger.info(' %s new updates in: %s', len(tmsgs), msgid) except LookupError: logger.debug(' 0 new updates in: %s', msgid) continue for tmsg in tmsgs: - tmsgid = peebz.get_msgid(tmsg) + tmsgid = bugspray.get_msgid(tmsg) if tmsgid in seen_msgids: logger.debug('Already seen %s', tmsgid) continue seen_msgids.add(tmsgid) try: - peebz.db_get_bid_cid_by_msgid(tmsgid) + bugspray.db_get_bid_cid_by_msgid(tmsgid) logger.debug('%s has already been processed', tmsgid) continue except LookupError: @@ -85,24 +85,24 @@ def update_component(product: str, component: str, dry_run: bool = False): qquery = urllib.parse.quote_plus(query) query_url = url.rstrip('/') + f'/?x=m&q={qquery}' try: - msgs = peebz.pi_get_query_results(query_url) + msgs = bugspray.pi_get_query_results(query_url) for msg in msgs: - msgid = peebz.get_msgid(msg) + msgid = bugspray.get_msgid(msg) if msgid in seen_msgids: logger.debug('Already seen %s', msgid) continue # New thing to track! seen_msgids.add(msgid) - author = peebz.msg_get_author(msg) + author = bugspray.msg_get_author(msg) fromaddr = author[1] - if not peebz.bz_check_user_allowed(fromaddr, product, component): + if not bugspray.bz_check_user_allowed(fromaddr, product, component): 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()) if trigger_res: - payload = peebz.msg_get_payload(msg) + payload = bugspray.msg_get_payload(msg) found = False for trigger_re in trigger_res: matches = re.search(trigger_re, payload, flags=re.I | re.M) @@ -117,12 +117,12 @@ def update_component(product: str, component: str, dry_run: bool = False): # Retrieve and queue up the entire thread try: - tmsgs = peebz.pi_get_sorted_thread(url, msgid) + tmsgs = bugspray.pi_get_sorted_thread(url, msgid) except LookupError: logger.debug('No results returned for msgid=%s', msgid) continue for tmsg in tmsgs: - tmsgid = peebz.get_msgid(tmsg) + tmsgid = bugspray.get_msgid(tmsg) seen_msgids.add(tmsgid) updates.append(tmsg) @@ -133,7 +133,7 @@ def update_component(product: str, component: str, dry_run: bool = False): # Give a 10-minute overlap buffer bufferago = now - datetime.timedelta(minutes=10) lastdt = bufferago.strftime('%Y%m%d%H%M%S') - peebz.db_store_query_last_check(product, component, lastdt) + bugspray.db_store_query_last_check(product, component, lastdt) if not updates: logger.info('No new messages to add to bugzilla for %s/%s', product, component) @@ -141,11 +141,11 @@ def update_component(product: str, component: str, dry_run: bool = False): for msg in updates: logger.debug('Recording %s', msg.get('Subject')) - peebz.parse.process_rfc2822(msg, product, component, dry_run=dry_run) + bugspray.parse.process_rfc2822(msg, product, component, dry_run=dry_run) def main(cmdargs: argparse.Namespace): - config = peebz.get_config() + config = bugspray.get_config() # Iterate all components for bz_product, bz_components in config['components'].items(): for bz_component in bz_components.keys(): diff --git a/default.config.toml b/default.config.toml index 8828990..77e9e12 100644 --- a/default.config.toml +++ b/default.config.toml @@ -1,5 +1,5 @@ [db] -dburl = 'sqlite:////home/user/work/temp/peebz.sqlite3' +dburl = 'sqlite:////home/user/work/temp/bugspray.sqlite3' [notify] neverto = ['*@kernel-bugs.*', 'bugbot@kernel.org'] @@ -25,7 +25,7 @@ maintainers_url = 'https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linu deny = [ 'text/html', 'application/*-signature' ] [logging] -logfile = 'peebz.log' +logfile = 'bugspray.log' loglevel = 'info' [components.'Linux'.'Kernel'] diff --git a/pyproject.toml b/pyproject.toml index 37bd94a..1921bbb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] -name = 'peebz' +name = 'bugspray' version = '0.1' -description = 'A bridge between public-inbox, bugzilla, and git' +description = 'A multi-way bridge between public-inbox, bugzilla, and git' readme = 'README.md' requires-python = '>=3.8' license = {file = 'COPYING'} @@ -23,7 +23,7 @@ classifiers = [ dependencies = [ 'b4 >= 0.12.2, < 1.0', 'Pygments >= 2.14.0, < 3.0', - 'requests >= 2.28', + 'requests >= 2.31', 'sqlalchemy >= 1.4, < 2.0', # Conditional to python version 'tomli >= 2.0; python_version < "3.11"', @@ -33,9 +33,9 @@ dependencies = [ #] [project.urls] -'Homepage' = 'https://git.kernel.org/pub/scm/utils/peebz/peebz.git/' -'Source' = 'https://git.kernel.org/pub/scm/utils/peebz/peebz.git' +'Homepage' = 'https://git.kernel.org/pub/scm/utils/bugspray/bugspray.git/' +'Source' = 'https://git.kernel.org/pub/scm/utils/bugspray/bugspray.git' 'Community' = 'https://lore.kernel.org/tools' [project.scripts] -peebz = 'peebz.command:cmd' +bugspray = 'bugspray.command:cmd' diff --git a/requirements.txt b/requirements.txt index cab6f85..46e3d13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ -b4>=0.12.2,<1.0 -Pygments>=2.14.0,<3.0 -requests>=2.28 -sqlalchemy>=1.4,<2.0 +b4==0.12.4 +Pygments==2.16.1 +requests>=2.31 +sqlalchemy==2.0.22 tomli>=2.0; python_version < '3.11' |