← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/bug-duplicate-header into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/bug-duplicate-header into lp:launchpad.

Commit message:
Add X-Launchpad-Bug-Duplicate header to notifications about duplicate bugs.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #363995 in Launchpad itself: "Please add X-Launchpad-Duplicate header to bug mails"
  https://bugs.launchpad.net/launchpad/+bug/363995

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/bug-duplicate-header/+merge/264609

Add X-Launchpad-Bug-Duplicate header to notifications about duplicate bugs.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/bug-duplicate-header into lp:launchpad.
=== modified file 'lib/lp/bugs/doc/bugnotification-sending.txt'
--- lib/lp/bugs/doc/bugnotification-sending.txt	2015-06-27 04:10:49 +0000
+++ lib/lp/bugs/doc/bugnotification-sending.txt	2015-07-13 16:24:56 +0000
@@ -19,15 +19,16 @@
 And let's define functions to make printing out the notifications
 easier.
 
-    >>> def print_notification_headers(email_notification):
+    >>> def print_notification_headers(email_notification, extra_headers=[]):
     ...     for header in ['To', 'From', 'Subject',
     ...                    'X-Launchpad-Message-Rationale',
-    ...                    'X-Launchpad-Subscription']:
+    ...                    'X-Launchpad-Subscription'] + extra_headers:
     ...         if email_notification[header]:
     ...             print "%s: %s" % (header, email_notification[header])
 
-    >>> def print_notification(email_notification):
-    ...     print_notification_headers(email_notification)
+    >>> def print_notification(email_notification, extra_headers=[]):
+    ...     print_notification_headers(
+    ...         email_notification, extra_headers=extra_headers)
     ...     print
     ...     print email_notification.get_payload(decode=True)
     ...     print "-" * 70
@@ -349,10 +350,32 @@
     >>> with lp_dbuser():
     ...     new_bug = ubuntu.createBug(params)
 
+No duplicate information is included.
+
+    >>> notifications = getUtility(
+    ...     IBugNotificationSet).getNotificationsToSend()
+    >>> len(notifications)
+    1
+
+    >>> for bug_notifications, omitted, messages in (
+    ...     get_email_notifications(notifications)):
+    ...     for message in messages:
+    ...         print_notification(
+    ...             message, extra_headers=['X-Launchpad-Bug-Duplicate'])
+    To: test@xxxxxxxxxxxxx
+    From: Sample Person <16@xxxxxxxxxxxxxxxxxx>
+    Subject: [Bug 16] [NEW] new bug
+    X-Launchpad-Message-Rationale: Subscriber
+    <BLANKLINE>
+    Public bug reported:
+    ...
+    ----------------------------------------------------------------------
+
+    >>> flush_notifications()
+
 If a bug is a duplicate of another bug, a marker gets inserted at the
 top of the email:
 
-    >>> flush_notifications()
     >>> with lp_dbuser():
     ...     new_bug.markAsDuplicate(bug_one)
     >>> comment = getUtility(IMessageSet).fromText(
@@ -367,11 +390,13 @@
     >>> for bug_notifications, omitted, messages in (
     ...     get_email_notifications(notifications)):
     ...     for message in messages:
-    ...         print_notification(message)
+    ...         print_notification(
+    ...             message, extra_headers=['X-Launchpad-Bug-Duplicate'])
     To: test@xxxxxxxxxxxxx
     From: Sample Person <16@xxxxxxxxxxxxxxxxxx>
     Subject: [Bug 16] subject
     X-Launchpad-Message-Rationale: Subscriber
+    X-Launchpad-Bug-Duplicate: 1
     <BLANKLINE>
     *** This bug is a duplicate of bug 1 ***
         http://bugs.launchpad.dev/bugs/1

=== modified file 'lib/lp/bugs/mail/bugnotificationbuilder.py'
--- lib/lp/bugs/mail/bugnotificationbuilder.py	2015-07-06 17:27:09 +0000
+++ lib/lp/bugs/mail/bugnotificationbuilder.py	2015-07-13 16:24:56 +0000
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2010-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Bug notification building code."""
@@ -157,6 +157,10 @@
                     '%s (%s)' % (event_creator.displayname,
                         event_creator.name)))
 
+        if bug.duplicateof is not None:
+            self.common_headers.append(
+                ('X-Launchpad-Bug-Duplicate', str(bug.duplicateof.id)))
+
     def build(self, from_address, to_address, body, subject, email_date,
               rationale=None, references=None, message_id=None, filters=None):
         """Construct the notification.


Follow ups