bz2pi: don't crash when no recipients found
If there is no "alwayscc", fall back to "recipients". If all else fails,
don't crash, but bail out with a message in the logs.
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
diff --git a/src/bugspray/__init__.py b/src/bugspray/__init__.py
index abdf18c..0033398 100644
--- a/src/bugspray/__init__.py
+++ b/src/bugspray/__init__.py
@@ -772,6 +772,14 @@
config['components'][product][component]['alwayscc'])
except KeyError:
pass
+ if not recip:
+ try:
+ recip.update(config['components'][product][component]['recipients'])
+ logger.debug('added %s/%s fallback recipients: %s', product, component,
+ config['components'][product][component]['recipients'])
+ except KeyError:
+ pass
+
return recip
@@ -874,13 +882,16 @@
def notify_bug(bid: int, cid: Optional[int], msg: email.message.EmailMessage, inre_cid: Optional[int] = None,
- dry_run: bool = False) -> str:
+ dry_run: bool = False) -> Optional[str]:
bdata = bz_get_bug(bid, resolve_dupes=True)
config = get_config()
if not msg.get('From'):
msg['From'] = config['notify'].get('fromaddr')
if not msg.get('To'):
recipients = get_bug_recipients(bid)
+ if not recipients:
+ logger.info('No recipients for bug %s, not notifying', bid)
+ return None
msg['To'] = b4.format_addrs([('', x) for x in recipients])
if not msg.get('Message-ID'):
msg['Message-ID'] = make_msgid(bid, cid)