Merge lp:~thumper/launchpad/new-code-import-email-show-type into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: no longer in the source branch.
Merged at revision: 10465
Proposed branch: lp:~thumper/launchpad/new-code-import-email-show-type
Merge into: lp:launchpad
Diff against target: 194 lines (+143/-6)
4 files modified
lib/canonical/launchpad/emailtemplates/new-code-import.txt (+3/-1)
lib/lp/code/doc/codeimport.txt (+6/-3)
lib/lp/code/mail/codeimport.py (+18/-2)
lib/lp/code/mail/tests/test_codeimport.py (+116/-0)
To merge this branch: bzr merge lp:~thumper/launchpad/new-code-import-email-show-type
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+20938@code.launchpad.net

Commit message

Send the rcs_type and location in the new code import email.

Description of the change

New code imports should include the type and the import location.

Testing is easy: register a new code import and check the email.

To post a comment you must log in.
Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Hi Tim,

Yay for this :)

Two comments:

I think "CVS" would be better than "Concurrent Versions System" in the email and "Subversion" better than "Subversion via bzr-svn". For the former, one could even change the title of the enum, although that will break some tests.

The second point is much simpler: there is too much vertical whitespace at the end of the test file :)

But in general, very happy to see this move.

Cheers,
mwh

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/canonical/launchpad/emailtemplates/new-code-import.txt'
2--- lib/canonical/launchpad/emailtemplates/new-code-import.txt 2008-06-20 18:54:03 +0000
3+++ lib/canonical/launchpad/emailtemplates/new-code-import.txt 2010-03-09 07:40:54 +0000
4@@ -1,5 +1,7 @@
5-A new code import has been requested by %(person)s:
6+A new %(rcs_type)s code import has been requested by %(person)s:
7 %(branch)s
8+from
9+ %(location)s
10
11 --
12 You are getting this email because you are a member of the vcs-imports team.
13
14=== modified file 'lib/lp/code/doc/codeimport.txt'
15--- lib/lp/code/doc/codeimport.txt 2010-03-05 03:51:59 +0000
16+++ lib/lp/code/doc/codeimport.txt 2010-03-09 07:40:54 +0000
17@@ -98,10 +98,13 @@
18 New code import: firefox/trunk-cvs
19 >>> print message['X-Launchpad-Message-Rationale']
20 Operator @vcs-imports
21- >>> print message.get_payload()
22- A new code import has been requested by No Privileges Person:
23+ >>> print message.get_payload(decode=True)
24+ A new CVS code import has been requested by No Privileges Person:
25 http://code.launchpad.dev/~no-priv/firefox/trunk-cvs
26- -- =
27+ from
28+ :pserver:anonymous@cvs.example.com:/cvsroot, hello
29+ <BLANKLINE>
30+ --
31 You are getting this email because you are a member of the vcs-imports team.
32
33 Creating a CodeImport object creates a corresponding CodeImportEvent.
34
35=== modified file 'lib/lp/code/mail/codeimport.py'
36--- lib/lp/code/mail/codeimport.py 2010-01-12 03:46:21 +0000
37+++ lib/lp/code/mail/codeimport.py 2010-03-09 07:40:54 +0000
38@@ -32,9 +32,23 @@
39 user = IPerson(event.user)
40 subject = 'New code import: %s/%s' % (
41 code_import.product.name, code_import.branch.name)
42+ if code_import.rcs_type == RevisionControlSystems.CVS:
43+ location = '%s, %s' % (code_import.cvs_root, code_import.cvs_module)
44+ else:
45+ location = code_import.url
46+ rcs_type_map = {
47+ RevisionControlSystems.CVS: 'CVS',
48+ RevisionControlSystems.SVN: 'subversion',
49+ RevisionControlSystems.BZR_SVN: 'subversion',
50+ RevisionControlSystems.GIT: 'git',
51+ RevisionControlSystems.HG: 'mercurial',
52+ }
53 body = get_email_template('new-code-import.txt') % {
54 'person': code_import.registrant.displayname,
55- 'branch': canonical_url(code_import.branch)}
56+ 'branch': canonical_url(code_import.branch),
57+ 'rcs_type': rcs_type_map[code_import.rcs_type],
58+ 'location': location,
59+ }
60
61 from_address = format_address(
62 user.displayname, user.preferredemail.email)
63@@ -42,7 +56,9 @@
64 vcs_imports = getUtility(ILaunchpadCelebrities).vcs_imports
65 headers = {'X-Launchpad-Branch': code_import.branch.unique_name,
66 'X-Launchpad-Message-Rationale':
67- 'Operator @%s' % vcs_imports.name}
68+ 'Operator @%s' % vcs_imports.name,
69+ 'X-Launchpad-Notification-Type': 'code-import',
70+ }
71 for address in get_contact_email_addresses(vcs_imports):
72 simple_sendmail(from_address, address, subject, body, headers)
73
74
75=== added file 'lib/lp/code/mail/tests/test_codeimport.py'
76--- lib/lp/code/mail/tests/test_codeimport.py 1970-01-01 00:00:00 +0000
77+++ lib/lp/code/mail/tests/test_codeimport.py 2010-03-09 07:40:54 +0000
78@@ -0,0 +1,116 @@
79+# Copyright 2010 Canonical Ltd. This software is licensed under the
80+# GNU Affero General Public License version 3 (see the file LICENSE).
81+
82+"""Tests for code import related mailings"""
83+
84+from email import message_from_string
85+import transaction
86+from unittest import TestLoader
87+
88+from canonical.testing import DatabaseFunctionalLayer
89+
90+from lp.code.enums import RevisionControlSystems
91+from lp.services.mail import stub
92+from lp.testing import login_person, TestCaseWithFactory
93+
94+
95+class TestNewCodeImports(TestCaseWithFactory):
96+ """Test the emails sent out for new code imports."""
97+
98+ layer = DatabaseFunctionalLayer
99+
100+ def test_cvs_import(self):
101+ # Test the email for a new CVS import.
102+ eric = self.factory.makePerson(name='eric')
103+ fooix = self.factory.makeProduct(name='fooix')
104+ # Eric needs to be logged in for the mail to be sent.
105+ login_person(eric)
106+ code_import = self.factory.makeCodeImport(
107+ cvs_root=':pserver:anonymouse@cvs.example.com:/cvsroot',
108+ cvs_module='a_module', branch_name='import',
109+ product=fooix, registrant=eric)
110+ transaction.commit()
111+ msg = message_from_string(stub.test_emails[0][2])
112+ self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
113+ self.assertEqual('~eric/fooix/import', msg['X-Launchpad-Branch'])
114+ self.assertEqual(
115+ 'A new CVS code import has been requested by Eric:\n'
116+ ' http://code.launchpad.dev/~eric/fooix/import\n'
117+ 'from\n'
118+ ' :pserver:anonymouse@cvs.example.com:/cvsroot, a_module\n'
119+ '\n'
120+ '-- \nYou are getting this email because you are a member of the '
121+ 'vcs-imports team.\n', msg.get_payload(decode=True))
122+
123+ def test_svn_import(self):
124+ # Test the email for a new subversion import.
125+ eric = self.factory.makePerson(name='eric')
126+ fooix = self.factory.makeProduct(name='fooix')
127+ # Eric needs to be logged in for the mail to be sent.
128+ login_person(eric)
129+ code_import = self.factory.makeCodeImport(
130+ svn_branch_url='svn://svn.example.com/fooix/trunk',
131+ branch_name='trunk', product=fooix, registrant=eric,
132+ rcs_type=RevisionControlSystems.BZR_SVN)
133+ transaction.commit()
134+ msg = message_from_string(stub.test_emails[0][2])
135+ self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
136+ self.assertEqual('~eric/fooix/trunk', msg['X-Launchpad-Branch'])
137+ self.assertEqual(
138+ 'A new subversion code import has been requested by Eric:\n'
139+ ' http://code.launchpad.dev/~eric/fooix/trunk\n'
140+ 'from\n'
141+ ' svn://svn.example.com/fooix/trunk\n'
142+ '\n'
143+ '-- \nYou are getting this email because you are a member of the '
144+ 'vcs-imports team.\n', msg.get_payload(decode=True))
145+
146+ def test_git_import(self):
147+ # Test the email for a new git import.
148+ eric = self.factory.makePerson(name='eric')
149+ fooix = self.factory.makeProduct(name='fooix')
150+ # Eric needs to be logged in for the mail to be sent.
151+ login_person(eric)
152+ code_import = self.factory.makeCodeImport(
153+ git_repo_url='git://git.example.com/fooix.git',
154+ branch_name='master', product=fooix, registrant=eric)
155+ transaction.commit()
156+ msg = message_from_string(stub.test_emails[0][2])
157+ self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
158+ self.assertEqual('~eric/fooix/master', msg['X-Launchpad-Branch'])
159+ self.assertEqual(
160+ 'A new git code import has been requested '
161+ 'by Eric:\n'
162+ ' http://code.launchpad.dev/~eric/fooix/master\n'
163+ 'from\n'
164+ ' git://git.example.com/fooix.git\n'
165+ '\n'
166+ '-- \nYou are getting this email because you are a member of the '
167+ 'vcs-imports team.\n', msg.get_payload(decode=True))
168+
169+ def test_hg_import(self):
170+ # Test the email for a new hg import.
171+ eric = self.factory.makePerson(name='eric')
172+ fooix = self.factory.makeProduct(name='fooix')
173+ # Eric needs to be logged in for the mail to be sent.
174+ login_person(eric)
175+ code_import = self.factory.makeCodeImport(
176+ hg_repo_url='http://hg.example.com/fooix.hg',
177+ branch_name='master', product=fooix, registrant=eric)
178+ transaction.commit()
179+ msg = message_from_string(stub.test_emails[0][2])
180+ self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
181+ self.assertEqual('~eric/fooix/master', msg['X-Launchpad-Branch'])
182+ self.assertEqual(
183+ 'A new mercurial code import has been requested '
184+ 'by Eric:\n'
185+ ' http://code.launchpad.dev/~eric/fooix/master\n'
186+ 'from\n'
187+ ' http://hg.example.com/fooix.hg\n'
188+ '\n'
189+ '-- \nYou are getting this email because you are a member of the '
190+ 'vcs-imports team.\n', msg.get_payload(decode=True))
191+
192+
193+def test_suite():
194+ return TestLoader().loadTestsFromName(__name__)