Merge lp:~thumper/launchpad/initial-mp-email-text-alignment into lp:launchpad

Proposed by Tim Penhey
Status: Merged
Approved by: Tim Penhey
Approved revision: not available
Merged at revision: 10316
Proposed branch: lp:~thumper/launchpad/initial-mp-email-text-alignment
Merge into: lp:launchpad
Diff against target: 88 lines (+48/-7)
2 files modified
lib/lp/code/mail/branchmergeproposal.py (+30/-6)
lib/lp/code/mail/tests/test_branchmergeproposal.py (+18/-1)
To merge this branch: bzr merge lp:~thumper/launchpad/initial-mp-email-text-alignment
Reviewer Review Type Date Requested Status
Michael Hudson-Doyle Approve
Review via email: mp+19303@code.launchpad.net

Commit message

Fix the alignment of the related bugs and requested reviews in the initial merge proposal email.

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

A simple fix to the outgoing email for a new merge proposal to make sure that the related bugs and requested reviews use the same formatting.

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

Looks fine to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/code/mail/branchmergeproposal.py'
2--- lib/lp/code/mail/branchmergeproposal.py 2009-11-12 21:27:16 +0000
3+++ lib/lp/code/mail/branchmergeproposal.py 2010-02-14 22:36:21 +0000
4@@ -237,9 +237,36 @@
5 params['diff_cutoff_warning'] = (
6 "The attached diff has been truncated due to its size.")
7
8+ params['reviews'] = self._getRequestedReviews()
9 params['related_bugs'] = self._getRelatedBugs()
10 return params
11
12+ def _formatExtraInformation(self, heading, chunks):
13+ """Consistently indent the chunks with the heading.
14+
15+ Used to provide consistent indentation for requested reviews and
16+ related bugs.
17+ """
18+ if len(chunks) == 0:
19+ return ''
20+ else:
21+ info = ''.join(' %s\n' % value for value in chunks)
22+ return '%s\n%s' % (heading, info)
23+
24+ def _getRequestedReviews(self):
25+ """Return a string describing the requested reviews, if any."""
26+ requested_reviews = []
27+ for review in self.requested_reviews:
28+ reviewer = review.reviewer
29+ if review.review_type is None:
30+ requested_reviews.append(reviewer.unique_displayname)
31+ else:
32+ requested_reviews.append(
33+ "%s: %s" % (reviewer.unique_displayname,
34+ review.review_type))
35+ return self._formatExtraInformation(
36+ 'Requested reviews:', requested_reviews)
37+
38 def _getRelatedBugs(self):
39 """Return a string describing related bugs, if any.
40
41@@ -247,12 +274,9 @@
42 """
43 bug_chunks = []
44 for bug in self.merge_proposal.related_bugs:
45- bug_chunks.append(' #%d %s\n' % (bug.id, bug.title))
46- bug_chunks.append(' %s\n' % canonical_url(bug))
47- if len(bug_chunks) == 0:
48- return ''
49- else:
50- return 'Related bugs:\n' + ''.join(bug_chunks)
51+ bug_chunks.append('#%d %s' % (bug.id, bug.title))
52+ bug_chunks.append(canonical_url(bug))
53+ return self._formatExtraInformation('Related bugs:', bug_chunks)
54
55 def _getTemplateParams(self, email):
56 """Return a dict of values to use in the body and subject."""
57
58=== modified file 'lib/lp/code/mail/tests/test_branchmergeproposal.py'
59--- lib/lp/code/mail/tests/test_branchmergeproposal.py 2009-10-28 20:13:39 +0000
60+++ lib/lp/code/mail/tests/test_branchmergeproposal.py 2010-02-14 22:36:21 +0000
61@@ -135,9 +135,26 @@
62 mailer = BMPMailer.forCreation(bmp, bmp.registrant)
63 ctrl = mailer.generateEmail('baz.quxx@example.com', subscriber)
64 self.assertIn(
65- 'Requested reviews:\n Review-person (review-person)\n\n-- \n',
66+ '\nRequested reviews:\n Review-person (review-person)\n\n-- \n',
67 ctrl.body)
68
69+ def test_forCreation_with_review_request_and_bug(self):
70+ """Correctly format list of reviewers and bug info."""
71+ bmp, subscriber = self.makeProposalWithSubscriber()
72+ bug = self.factory.makeBug(title='I am a bug')
73+ bmp.source_branch.linkBug(bug, bmp.registrant)
74+ reviewer = self.factory.makePerson(name='review-person')
75+ vote_reference = bmp.nominateReviewer(reviewer, bmp.registrant, None)
76+ mailer = BMPMailer.forCreation(bmp, bmp.registrant)
77+ ctrl = mailer.generateEmail('baz.quxx@example.com', subscriber)
78+ expected = (
79+ '\nRequested reviews:'
80+ '\n Review-person (review-person)'
81+ '\nRelated bugs:'
82+ '\n #%d I am a bug'
83+ '\n %s\n\n--' % (bug.id, canonical_url(bug)))
84+ self.assertIn(expected, ctrl.body)
85+
86 def test_forCreation_with_prerequisite_branch(self):
87 """Correctly format list of reviewers."""
88 bmp, subscriber = self.makeProposalWithSubscriber(prerequisite=True)