Merge lp:~wgrant/launchpad/ic-fixes into lp:launchpad

Proposed by William Grant
Status: Merged
Merged at revision: 17017
Proposed branch: lp:~wgrant/launchpad/ic-fixes
Merge into: lp:launchpad
Diff against target: 154 lines (+21/-20)
4 files modified
lib/lp/code/javascript/branchmergeproposal.inlinecomments.js (+6/-5)
lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js (+2/-2)
lib/lp/code/mail/codereviewcomment.py (+3/-4)
lib/lp/code/mail/tests/test_codereviewcomment.py (+10/-9)
To merge this branch: bzr merge lp:~wgrant/launchpad/ic-fixes
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+220410@code.launchpad.net

Commit message

Turn inline comments publish checkbox label into a real label, ensure that drafts are refreshed after publishing, and fix off-by-one error in inline comment email formatting.

Description of the change

Fix three easy bugs in inline comments:

 - Turn 'Include X diff comments' into a label for the checkbox so it's possible to click without incredible precision.

 - Ensure that drafts are refreshed from the server after publishing them, as we otherwise end up with weird ghost drafts that either don't appear or disappear until refresh.

 - Fix inline comment off-by-one error. Comment dicts are 1-indexed, but the email formatter was accidentally just skipping line 0 instead of numbering from 1.

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/code/javascript/branchmergeproposal.inlinecomments.js'
2--- lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-05-21 03:49:52 +0000
3+++ lib/lp/code/javascript/branchmergeproposal.inlinecomments.js 2014-05-21 09:37:00 +0000
4@@ -272,17 +272,17 @@
5 Y.fire('CodeReviewComment.SET_DISABLED', true);
6 return;
7 }
8- var text = 'Include ' + n_drafts + ' diff comment';
9+ var text = ' Include ' + n_drafts + ' diff comment';
10 if (n_drafts > 1) text += 's';
11- var label = Y.Node.create('<a />')
12- .set('text', text);
13 var checkbox = Y.Node.create(
14 '<input id="field.publish_inline_comments"' +
15 'name="field.publish_inline_comments"' +
16 'type="checkbox" class="checkboxType"' +
17 'checked=""></input>')
18- this.get('contentBox').append(checkbox);
19- this.get('contentBox').append(label);
20+ var label = Y.Node.create(
21+ '<label for="field.publish_inline_comments" />')
22+ .set('text', text);
23+ this.get('contentBox').append(checkbox).append(label);
24 Y.fire('CodeReviewComment.SET_DISABLED', false);
25 },
26
27@@ -463,6 +463,7 @@
28 }
29 namespace.cleanup_comments();
30 namespace.populate_comments();
31+ namespace.populate_drafts();
32 this._connectScrollers();
33 },
34
35
36=== modified file 'lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js'
37--- lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-05-21 01:58:44 +0000
38+++ lib/lp/code/javascript/tests/test_branchmergeproposal.inlinecomments.js 2014-05-21 09:37:00 +0000
39@@ -425,13 +425,13 @@
40 // A event is fired when the inlinecomments set changes.
41 Y.fire('inlinecomment.UPDATED');
42 Y.Assert.areEqual(
43- 'Include 1 diff comment', container.get('text'));
44+ ' Include 1 diff comment', container.get('text'));
45 Y.Assert.isNotNull(container.one('[type=checkbox]'));
46 // Adding another draft.
47 module.create_row({'line_number': '2', 'text': 'another'});
48 Y.fire('inlinecomment.UPDATED');
49 Y.Assert.areEqual(
50- 'Include 2 diff comments', container.get('text'));
51+ ' Include 2 diff comments', container.get('text'));
52 Y.Assert.isNotNull(container.one('[type=checkbox]'));
53 // Removing all drafts.
54 module.cleanup_comments();
55
56=== modified file 'lib/lp/code/mail/codereviewcomment.py'
57--- lib/lp/code/mail/codereviewcomment.py 2014-05-21 01:42:39 +0000
58+++ lib/lp/code/mail/codereviewcomment.py 2014-05-21 09:37:00 +0000
59@@ -173,10 +173,9 @@
60 """Return a formatted text section with contextualized comments."""
61 result_lines = []
62 diff_lines = diff_text.splitlines()
63- for i in range(1, len(diff_lines)):
64- result_lines.append(
65- u'> {0}'.format(diff_lines[i].decode('utf-8', 'replace')))
66- comment = comments.get(str(i))
67+ for num, line in enumerate(diff_lines, 1):
68+ result_lines.append(u'> {0}'.format(line.decode('utf-8', 'replace')))
69+ comment = comments.get(str(num))
70 if comment is not None:
71 result_lines.append('')
72 result_lines.extend(comment.splitlines())
73
74=== modified file 'lib/lp/code/mail/tests/test_codereviewcomment.py'
75--- lib/lp/code/mail/tests/test_codereviewcomment.py 2014-05-21 01:42:39 +0000
76+++ lib/lp/code/mail/tests/test_codereviewcomment.py 2014-05-21 09:37:00 +0000
77@@ -245,7 +245,7 @@
78 set_feature_flag(u'code.inline_diff_comments.enabled', u'enabled')
79
80 comment = self.makeCommentWithInlineComments(
81- inline_comments={'1': u'Is this from Planet Earth\xa9 ?'})
82+ inline_comments={'2': u'Is this from Planet Earth\xa9 ?'})
83 mailer = CodeReviewCommentMailer.forCreation(comment)
84 commenter = comment.branch_merge_proposal.registrant
85 ctrl = mailer.generateEmail(
86@@ -255,6 +255,7 @@
87 '',
88 'Diff comments:',
89 '',
90+ "> === zbqvsvrq svyr 'yvo/yc/pbqr/vagresnprf/qvss.cl'",
91 '> --- yvo/yc/pbqr/vagresnprf/qvss.cl '
92 '2009-10-01 13:25:12 +0000',
93 '',
94@@ -263,7 +264,7 @@
95 '> +++ yvo/yc/pbqr/vagresnprf/qvss.cl '
96 '2010-02-02 15:48:56 +0000'
97 ]
98- self.assertEqual(expected_lines, ctrl.body.splitlines()[1:9])
99+ self.assertEqual(expected_lines, ctrl.body.splitlines()[1:10])
100
101 def test_generateEmailWithInlineComments_feature_disabled(self):
102 """Inline comments are not considered if the flag is not enabled."""
103@@ -434,7 +435,7 @@
104 '',
105 'Diff comments:',
106 '',
107- '> +++ bar\t1969-12-31 19:00:00.000000000 -0500'],
108+ '> --- bar\t2009-08-26 15:53:34.000000000 -0400'],
109 header)
110 footer = section[-2:]
111 self.assertEqual(
112@@ -445,7 +446,7 @@
113 def test_single_line_comment(self):
114 # The inline comments are correctly contextualized in the diff.
115 # and prefixed with '>>> '
116- comments = {'1': u'\u03b4\u03bf\u03ba\u03b9\u03bc\u03ae'}
117+ comments = {'2': u'\u03b4\u03bf\u03ba\u03b9\u03bc\u03ae'}
118 self.assertEqual(
119 ['> +++ bar\t1969-12-31 19:00:00.000000000 -0500',
120 '',
121@@ -453,11 +454,11 @@
122 '',
123 '> @@ -1,3 +0,0 @@',
124 u'> -\xe5'],
125- self.getSection(comments).splitlines()[4:10])
126+ self.getSection(comments).splitlines()[5:11])
127
128 def test_multi_line_comment(self):
129 # Inline comments with multiple lines are rendered appropriately.
130- comments = {'1': 'Foo\nBar'}
131+ comments = {'2': 'Foo\nBar'}
132 self.assertEqual(
133 ['> +++ bar\t1969-12-31 19:00:00.000000000 -0500',
134 '',
135@@ -465,11 +466,11 @@
136 'Bar',
137 '',
138 '> @@ -1,3 +0,0 @@'],
139- self.getSection(comments).splitlines()[4:10])
140+ self.getSection(comments).splitlines()[5:11])
141
142 def test_multiple_comments(self):
143 # Multiple inline comments are redered appropriately.
144- comments = {'1': 'Foo', '2': 'Bar'}
145+ comments = {'2': 'Foo', '3': 'Bar'}
146 self.assertEqual(
147 ['> +++ bar\t1969-12-31 19:00:00.000000000 -0500',
148 '',
149@@ -479,4 +480,4 @@
150 '',
151 'Bar',
152 ''],
153- self.getSection(comments).splitlines()[4:12])
154+ self.getSection(comments).splitlines()[5:13])