[Tracker-discuss] [issue624] bpo emails contain useless non-github pull_request number - users want a link to actual github PR

Berker Peksag metatracker at psf.upfronthosting.co.za
Sat Jun 9 16:09:26 EDT 2018


Berker Peksag <berker.peksag at gmail.com> added the comment:

Here's patch to fix this issue.

Example output:

----------
components: +Tkinter
versions: +Python 2.4
pull_request: https://github.com/python/cpython/pull/341

Old version:

----------
components: +Tkinter
versions: +Python 2.4
pull_requests: +42

----------
nosy: +berker.peksag

_______________________________________________________
PSF Meta Tracker <metatracker at psf.upfronthosting.co.za>
<http://psf.upfronthosting.co.za/roundup/meta/issue624>
_______________________________________________________
-------------- next part --------------
diff --git a/detectors/sendmail.py b/detectors/sendmail.py
--- a/detectors/sendmail.py
+++ b/detectors/sendmail.py
@@ -1,8 +1,10 @@
+import re
+
 from roundup import roundupdb
 
 def determineNewMessages(cl, nodeid, oldvalues):
     ''' Figure a list of the messages that are being added to the given
         node in this transaction.
     '''
     messages = []
     if oldvalues is None:
@@ -32,16 +34,26 @@ def is_spam(db, msgid):
 
     msg = db.getnode("msg", msgid)
     if msg.has_key('spambayes_score') and \
            msg['spambayes_score'] > cutoff_score:
         return True
     return False
 
 
+def extract_pr_number(changenote):
+    # Example input for 'changenote':
+    #
+    # '\n----------\nmessage_count: 2.0 -> 3.0\npull_requests: +20\nversions: +Python 3.1'
+    match = re.search(r'pull_requests: \+(\d+)', changenote, flags=re.M|re.S)
+    if match is None:
+        return None
+    return match.group(1)
+
+
 def sendmail(db, cl, nodeid, oldvalues):
     """Send mail to various recipients, when changes occur:
 
     * For all changes (property-only, or with new message), send mail
       to all e-mail addresses defined in
       db.config.detectors['BUSYBODY_EMAIL']
 
     * For all changes (property-only, or with new message), send mail
@@ -70,19 +82,28 @@ def sendmail(db, cl, nodeid, oldvalues):
             pass
         oldfiles = []
         oldmsglist = []
     else:
         changenote = cl.generateChangeNote(nodeid, oldvalues)
         oldfiles = oldvalues.get('files', [])
         oldmsglist = oldvalues.get('messages', [])
 
-    # Silence nosy_count/message_count
     lines = changenote.splitlines()
-    changenote = '\n'.join(line for line in lines if '_count' not in line)
+
+    pr_number = extract_pr_number(changenote)
+    if pr_number is not None:
+        pr_number = db.pull_request.get(pr_number, 'number')
+        pr_url = 'pull_request: https://github.com/python/cpython/pull/%d' % pr_number
+        lines.append(pr_url)
+
+    # Silence nosy_count/message_count/pull_requests
+    changenote = '\n'.join(
+        line for line in lines if '_count' not in line and 'pull_requests' not in line
+    )
 
     newfiles = db.issue.get(nodeid, 'files', [])
     if oldfiles != newfiles:
         added = [fid for fid in newfiles if fid not in oldfiles]
         removed = [fid for fid in oldfiles if fid not in newfiles]
         filemsg = ""
 
         for fid in added:


More information about the Tracker-discuss mailing list