Merge lp:~thumper/launchpad/no-none-subject into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Michael Hudson-Doyle
Approved revision: not available
Merged at revision: 10366
Proposed branch: lp:~thumper/launchpad/no-none-subject
Merge into: lp:launchpad
Diff against target: 86 lines (+25/-9)
2 files modified
lib/lp/codehosting/scanner/email.py (+10/-5)
lib/lp/codehosting/scanner/tests/test_email.py (+15/-4)
To merge this branch: bzr merge lp:~thumper/launchpad/no-none-subject
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+19902@code.launchpad.net

Commit message

Stop using None as an email subject for some revision emails.

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

Simple fix to provide real subject lines to the emails that get sent out for the initial scan of a branch, and when revisions are removed off the mainline.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Makes sense to me.

Revision history for this message
Michael Hudson-Doyle (mwhudson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/codehosting/scanner/email.py'
2--- lib/lp/codehosting/scanner/email.py 2010-01-06 12:15:42 +0000
3+++ lib/lp/codehosting/scanner/email.py 2010-02-22 19:58:16 +0000
4@@ -38,15 +38,18 @@
5 if number_removed == 0:
6 return
7 if number_removed == 1:
8- contents = '1 revision was removed from the branch.'
9+ count = '1 revision'
10+ contents = '%s was removed from the branch.' % count
11 else:
12- contents = ('%d revisions were removed from the branch.'
13- % number_removed)
14+ count = '%d revisions' % number_removed
15+ contents = '%s were removed from the branch.' % count
16 # No diff is associated with the removed email.
17+ subject = "[Branch %s] %s removed" % (
18+ revisions_removed.db_branch.unique_name, count)
19 getUtility(IRevisionMailJobSource).create(
20 revisions_removed.db_branch, revno='removed',
21 from_address=config.canonical.noreply_from_address,
22- body=contents, perform_diff=False, subject=None)
23+ body=contents, perform_diff=False, subject=subject)
24
25
26 @adapter(events.TipChanged)
27@@ -62,9 +65,11 @@
28 message = ('First scan of the branch detected %s'
29 ' in the revision history of the branch.' %
30 revisions)
31+ subject = "[Branch %s] %s" % (
32+ tip_changed.db_branch.unique_name, revisions)
33 getUtility(IRevisionMailJobSource).create(
34 tip_changed.db_branch, 'initial',
35- config.canonical.noreply_from_address, message, False, None)
36+ config.canonical.noreply_from_address, message, False, subject)
37 else:
38 getUtility(IRevisionsAddedJobSource).create(
39 tip_changed.db_branch, tip_changed.db_branch.last_scanned_id,
40
41=== modified file 'lib/lp/codehosting/scanner/tests/test_email.py'
42--- lib/lp/codehosting/scanner/tests/test_email.py 2009-07-17 00:26:05 +0000
43+++ lib/lp/codehosting/scanner/tests/test_email.py 2010-02-22 19:58:16 +0000
44@@ -63,8 +63,12 @@
45 self.assertEqual(len(stub.test_emails), 1)
46 [initial_email] = stub.test_emails
47 expected = 'First scan of the branch detected 0 revisions'
48- email_body = email.message_from_string(initial_email[2]).get_payload()
49+ message = email.message_from_string(initial_email[2])
50+ email_body = message.get_payload()
51 self.assertTextIn(expected, email_body)
52+ self.assertEqual(
53+ '[Branch %s] 0 revisions' % self.db_branch.unique_name,
54+ message['Subject'])
55
56 def test_import_revision(self):
57 self.commitRevision()
58@@ -74,8 +78,12 @@
59 [initial_email] = stub.test_emails
60 expected = ('First scan of the branch detected 1 revision'
61 ' in the revision history of the=\n branch.')
62- email_body = email.message_from_string(initial_email[2]).get_payload()
63+ message = email.message_from_string(initial_email[2])
64+ email_body = message.get_payload()
65 self.assertTextIn(expected, email_body)
66+ self.assertEqual(
67+ '[Branch %s] 1 revision' % self.db_branch.unique_name,
68+ message['Subject'])
69
70 def test_import_uncommit(self):
71 self.commitRevision()
72@@ -88,9 +96,12 @@
73 self.assertEqual(len(stub.test_emails), 1)
74 [uncommit_email] = stub.test_emails
75 expected = '1 revision was removed from the branch.'
76- email_body = email.message_from_string(
77- uncommit_email[2]).get_payload()
78+ message = email.message_from_string(uncommit_email[2])
79+ email_body = message.get_payload()
80 self.assertTextIn(expected, email_body)
81+ self.assertEqual(
82+ '[Branch %s] 1 revision removed' % self.db_branch.unique_name,
83+ message['Subject'])
84
85 def test_import_recommit(self):
86 # When scanning the uncommit and new commit there should be an email