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

Proposed by Colin Watson
Status: Merged
Merged at revision: 17635
Proposed branch: lp:~cjwatson/launchpad/bug-duplicate-header
Merge into: lp:launchpad
Diff against target: 94 lines (+36/-7)
2 files modified
lib/lp/bugs/doc/bugnotification-sending.txt (+31/-6)
lib/lp/bugs/mail/bugnotificationbuilder.py (+5/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/bug-duplicate-header
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+264609@code.launchpad.net

Commit message

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

Description of the change

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

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/doc/bugnotification-sending.txt'
2--- lib/lp/bugs/doc/bugnotification-sending.txt 2015-06-27 04:10:49 +0000
3+++ lib/lp/bugs/doc/bugnotification-sending.txt 2015-07-13 16:24:56 +0000
4@@ -19,15 +19,16 @@
5 And let's define functions to make printing out the notifications
6 easier.
7
8- >>> def print_notification_headers(email_notification):
9+ >>> def print_notification_headers(email_notification, extra_headers=[]):
10 ... for header in ['To', 'From', 'Subject',
11 ... 'X-Launchpad-Message-Rationale',
12- ... 'X-Launchpad-Subscription']:
13+ ... 'X-Launchpad-Subscription'] + extra_headers:
14 ... if email_notification[header]:
15 ... print "%s: %s" % (header, email_notification[header])
16
17- >>> def print_notification(email_notification):
18- ... print_notification_headers(email_notification)
19+ >>> def print_notification(email_notification, extra_headers=[]):
20+ ... print_notification_headers(
21+ ... email_notification, extra_headers=extra_headers)
22 ... print
23 ... print email_notification.get_payload(decode=True)
24 ... print "-" * 70
25@@ -349,10 +350,32 @@
26 >>> with lp_dbuser():
27 ... new_bug = ubuntu.createBug(params)
28
29+No duplicate information is included.
30+
31+ >>> notifications = getUtility(
32+ ... IBugNotificationSet).getNotificationsToSend()
33+ >>> len(notifications)
34+ 1
35+
36+ >>> for bug_notifications, omitted, messages in (
37+ ... get_email_notifications(notifications)):
38+ ... for message in messages:
39+ ... print_notification(
40+ ... message, extra_headers=['X-Launchpad-Bug-Duplicate'])
41+ To: test@canonical.com
42+ From: Sample Person <16@bugs.launchpad.net>
43+ Subject: [Bug 16] [NEW] new bug
44+ X-Launchpad-Message-Rationale: Subscriber
45+ <BLANKLINE>
46+ Public bug reported:
47+ ...
48+ ----------------------------------------------------------------------
49+
50+ >>> flush_notifications()
51+
52 If a bug is a duplicate of another bug, a marker gets inserted at the
53 top of the email:
54
55- >>> flush_notifications()
56 >>> with lp_dbuser():
57 ... new_bug.markAsDuplicate(bug_one)
58 >>> comment = getUtility(IMessageSet).fromText(
59@@ -367,11 +390,13 @@
60 >>> for bug_notifications, omitted, messages in (
61 ... get_email_notifications(notifications)):
62 ... for message in messages:
63- ... print_notification(message)
64+ ... print_notification(
65+ ... message, extra_headers=['X-Launchpad-Bug-Duplicate'])
66 To: test@canonical.com
67 From: Sample Person <16@bugs.launchpad.net>
68 Subject: [Bug 16] subject
69 X-Launchpad-Message-Rationale: Subscriber
70+ X-Launchpad-Bug-Duplicate: 1
71 <BLANKLINE>
72 *** This bug is a duplicate of bug 1 ***
73 http://bugs.launchpad.dev/bugs/1
74
75=== modified file 'lib/lp/bugs/mail/bugnotificationbuilder.py'
76--- lib/lp/bugs/mail/bugnotificationbuilder.py 2015-07-06 17:27:09 +0000
77+++ lib/lp/bugs/mail/bugnotificationbuilder.py 2015-07-13 16:24:56 +0000
78@@ -1,4 +1,4 @@
79-# Copyright 2010-2011 Canonical Ltd. This software is licensed under the
80+# Copyright 2010-2015 Canonical Ltd. This software is licensed under the
81 # GNU Affero General Public License version 3 (see the file LICENSE).
82
83 """Bug notification building code."""
84@@ -157,6 +157,10 @@
85 '%s (%s)' % (event_creator.displayname,
86 event_creator.name)))
87
88+ if bug.duplicateof is not None:
89+ self.common_headers.append(
90+ ('X-Launchpad-Bug-Duplicate', str(bug.duplicateof.id)))
91+
92 def build(self, from_address, to_address, body, subject, email_date,
93 rationale=None, references=None, message_id=None, filters=None):
94 """Construct the notification.