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
=== modified file 'lib/canonical/launchpad/emailtemplates/new-code-import.txt'
--- lib/canonical/launchpad/emailtemplates/new-code-import.txt 2008-06-20 18:54:03 +0000
+++ lib/canonical/launchpad/emailtemplates/new-code-import.txt 2010-03-09 07:40:54 +0000
@@ -1,5 +1,7 @@
1A new code import has been requested by %(person)s:1A new %(rcs_type)s code import has been requested by %(person)s:
2 %(branch)s2 %(branch)s
3from
4 %(location)s
35
4-- 6--
5You are getting this email because you are a member of the vcs-imports team.7You are getting this email because you are a member of the vcs-imports team.
68
=== modified file 'lib/lp/code/doc/codeimport.txt'
--- lib/lp/code/doc/codeimport.txt 2010-03-05 03:51:59 +0000
+++ lib/lp/code/doc/codeimport.txt 2010-03-09 07:40:54 +0000
@@ -98,10 +98,13 @@
98 New code import: firefox/trunk-cvs98 New code import: firefox/trunk-cvs
99 >>> print message['X-Launchpad-Message-Rationale']99 >>> print message['X-Launchpad-Message-Rationale']
100 Operator @vcs-imports100 Operator @vcs-imports
101 >>> print message.get_payload()101 >>> print message.get_payload(decode=True)
102 A new code import has been requested by No Privileges Person:102 A new CVS code import has been requested by No Privileges Person:
103 http://code.launchpad.dev/~no-priv/firefox/trunk-cvs103 http://code.launchpad.dev/~no-priv/firefox/trunk-cvs
104 -- =104 from
105 :pserver:anonymous@cvs.example.com:/cvsroot, hello
106 <BLANKLINE>
107 --
105 You are getting this email because you are a member of the vcs-imports team.108 You are getting this email because you are a member of the vcs-imports team.
106109
107Creating a CodeImport object creates a corresponding CodeImportEvent.110Creating a CodeImport object creates a corresponding CodeImportEvent.
108111
=== modified file 'lib/lp/code/mail/codeimport.py'
--- lib/lp/code/mail/codeimport.py 2010-01-12 03:46:21 +0000
+++ lib/lp/code/mail/codeimport.py 2010-03-09 07:40:54 +0000
@@ -32,9 +32,23 @@
32 user = IPerson(event.user)32 user = IPerson(event.user)
33 subject = 'New code import: %s/%s' % (33 subject = 'New code import: %s/%s' % (
34 code_import.product.name, code_import.branch.name)34 code_import.product.name, code_import.branch.name)
35 if code_import.rcs_type == RevisionControlSystems.CVS:
36 location = '%s, %s' % (code_import.cvs_root, code_import.cvs_module)
37 else:
38 location = code_import.url
39 rcs_type_map = {
40 RevisionControlSystems.CVS: 'CVS',
41 RevisionControlSystems.SVN: 'subversion',
42 RevisionControlSystems.BZR_SVN: 'subversion',
43 RevisionControlSystems.GIT: 'git',
44 RevisionControlSystems.HG: 'mercurial',
45 }
35 body = get_email_template('new-code-import.txt') % {46 body = get_email_template('new-code-import.txt') % {
36 'person': code_import.registrant.displayname,47 'person': code_import.registrant.displayname,
37 'branch': canonical_url(code_import.branch)}48 'branch': canonical_url(code_import.branch),
49 'rcs_type': rcs_type_map[code_import.rcs_type],
50 'location': location,
51 }
3852
39 from_address = format_address(53 from_address = format_address(
40 user.displayname, user.preferredemail.email)54 user.displayname, user.preferredemail.email)
@@ -42,7 +56,9 @@
42 vcs_imports = getUtility(ILaunchpadCelebrities).vcs_imports56 vcs_imports = getUtility(ILaunchpadCelebrities).vcs_imports
43 headers = {'X-Launchpad-Branch': code_import.branch.unique_name,57 headers = {'X-Launchpad-Branch': code_import.branch.unique_name,
44 'X-Launchpad-Message-Rationale':58 'X-Launchpad-Message-Rationale':
45 'Operator @%s' % vcs_imports.name}59 'Operator @%s' % vcs_imports.name,
60 'X-Launchpad-Notification-Type': 'code-import',
61 }
46 for address in get_contact_email_addresses(vcs_imports):62 for address in get_contact_email_addresses(vcs_imports):
47 simple_sendmail(from_address, address, subject, body, headers)63 simple_sendmail(from_address, address, subject, body, headers)
4864
4965
=== added file 'lib/lp/code/mail/tests/test_codeimport.py'
--- lib/lp/code/mail/tests/test_codeimport.py 1970-01-01 00:00:00 +0000
+++ lib/lp/code/mail/tests/test_codeimport.py 2010-03-09 07:40:54 +0000
@@ -0,0 +1,116 @@
1# Copyright 2010 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).
3
4"""Tests for code import related mailings"""
5
6from email import message_from_string
7import transaction
8from unittest import TestLoader
9
10from canonical.testing import DatabaseFunctionalLayer
11
12from lp.code.enums import RevisionControlSystems
13from lp.services.mail import stub
14from lp.testing import login_person, TestCaseWithFactory
15
16
17class TestNewCodeImports(TestCaseWithFactory):
18 """Test the emails sent out for new code imports."""
19
20 layer = DatabaseFunctionalLayer
21
22 def test_cvs_import(self):
23 # Test the email for a new CVS import.
24 eric = self.factory.makePerson(name='eric')
25 fooix = self.factory.makeProduct(name='fooix')
26 # Eric needs to be logged in for the mail to be sent.
27 login_person(eric)
28 code_import = self.factory.makeCodeImport(
29 cvs_root=':pserver:anonymouse@cvs.example.com:/cvsroot',
30 cvs_module='a_module', branch_name='import',
31 product=fooix, registrant=eric)
32 transaction.commit()
33 msg = message_from_string(stub.test_emails[0][2])
34 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
35 self.assertEqual('~eric/fooix/import', msg['X-Launchpad-Branch'])
36 self.assertEqual(
37 'A new CVS code import has been requested by Eric:\n'
38 ' http://code.launchpad.dev/~eric/fooix/import\n'
39 'from\n'
40 ' :pserver:anonymouse@cvs.example.com:/cvsroot, a_module\n'
41 '\n'
42 '-- \nYou are getting this email because you are a member of the '
43 'vcs-imports team.\n', msg.get_payload(decode=True))
44
45 def test_svn_import(self):
46 # Test the email for a new subversion import.
47 eric = self.factory.makePerson(name='eric')
48 fooix = self.factory.makeProduct(name='fooix')
49 # Eric needs to be logged in for the mail to be sent.
50 login_person(eric)
51 code_import = self.factory.makeCodeImport(
52 svn_branch_url='svn://svn.example.com/fooix/trunk',
53 branch_name='trunk', product=fooix, registrant=eric,
54 rcs_type=RevisionControlSystems.BZR_SVN)
55 transaction.commit()
56 msg = message_from_string(stub.test_emails[0][2])
57 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
58 self.assertEqual('~eric/fooix/trunk', msg['X-Launchpad-Branch'])
59 self.assertEqual(
60 'A new subversion code import has been requested by Eric:\n'
61 ' http://code.launchpad.dev/~eric/fooix/trunk\n'
62 'from\n'
63 ' svn://svn.example.com/fooix/trunk\n'
64 '\n'
65 '-- \nYou are getting this email because you are a member of the '
66 'vcs-imports team.\n', msg.get_payload(decode=True))
67
68 def test_git_import(self):
69 # Test the email for a new git import.
70 eric = self.factory.makePerson(name='eric')
71 fooix = self.factory.makeProduct(name='fooix')
72 # Eric needs to be logged in for the mail to be sent.
73 login_person(eric)
74 code_import = self.factory.makeCodeImport(
75 git_repo_url='git://git.example.com/fooix.git',
76 branch_name='master', product=fooix, registrant=eric)
77 transaction.commit()
78 msg = message_from_string(stub.test_emails[0][2])
79 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
80 self.assertEqual('~eric/fooix/master', msg['X-Launchpad-Branch'])
81 self.assertEqual(
82 'A new git code import has been requested '
83 'by Eric:\n'
84 ' http://code.launchpad.dev/~eric/fooix/master\n'
85 'from\n'
86 ' git://git.example.com/fooix.git\n'
87 '\n'
88 '-- \nYou are getting this email because you are a member of the '
89 'vcs-imports team.\n', msg.get_payload(decode=True))
90
91 def test_hg_import(self):
92 # Test the email for a new hg import.
93 eric = self.factory.makePerson(name='eric')
94 fooix = self.factory.makeProduct(name='fooix')
95 # Eric needs to be logged in for the mail to be sent.
96 login_person(eric)
97 code_import = self.factory.makeCodeImport(
98 hg_repo_url='http://hg.example.com/fooix.hg',
99 branch_name='master', product=fooix, registrant=eric)
100 transaction.commit()
101 msg = message_from_string(stub.test_emails[0][2])
102 self.assertEqual('code-import', msg['X-Launchpad-Notification-Type'])
103 self.assertEqual('~eric/fooix/master', msg['X-Launchpad-Branch'])
104 self.assertEqual(
105 'A new mercurial code import has been requested '
106 'by Eric:\n'
107 ' http://code.launchpad.dev/~eric/fooix/master\n'
108 'from\n'
109 ' http://hg.example.com/fooix.hg\n'
110 '\n'
111 '-- \nYou are getting this email because you are a member of the '
112 'vcs-imports team.\n', msg.get_payload(decode=True))
113
114
115def test_suite():
116 return TestLoader().loadTestsFromName(__name__)