Merge lp:~bac/juju-gui/bug-1246685 into lp:juju-gui/experimental

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 1172
Proposed branch: lp:~bac/juju-gui/bug-1246685
Merge into: lp:juju-gui/experimental
Diff against target: 190 lines (+78/-39)
3 files modified
app/models/bundle.js (+50/-32)
test/data/browserbundle.json (+7/-6)
test/test_model_bundle.js (+21/-1)
To merge this branch: bzr merge lp:~bac/juju-gui/bug-1246685
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+193450@code.launchpad.net

Description of the change

Fix name/email address parsing for commits.

https://codereview.appspot.com/20170044/

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Reviewers: mp+193450_code.launchpad.net,

Message:
Please take a look.

Description:
Fix name/email address parsing for commits.

https://code.launchpad.net/~bac/juju-gui/bug-1246685/+merge/193450

(do not edit description out of merge proposal)

Please review this at https://codereview.appspot.com/20170044/

Affected files (+80, -39 lines):
   A [revision details]
   M app/models/bundle.js
   M test/data/browserbundle.json
   M test/test_model_bundle.js

Revision history for this message
Brad Crittenden (bac) wrote :

Author comments

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js
File app/models/bundle.js (left):

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#oldcode67
app/models/bundle.js:67: /**
Took Jeff's advice and moved back into the class for easy testing
access.

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js
File app/models/bundle.js (right):

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#newcode69
app/models/bundle.js:69: parseNameEmail: function(author) {
Actually we only care about the name as the currently don't display the
email address. However to match the data collected for charms I chose
to go ahead and squirrel it away.

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#newcode81
app/models/bundle.js:81: @method extractRecentCommits
I see I didn't document the changes arg. Will do so.

https://codereview.appspot.com/20170044/diff/1/test/data/browserbundle.json
File test/data/browserbundle.json (right):

https://codereview.appspot.com/20170044/diff/1/test/data/browserbundle.json#newcode9
test/data/browserbundle.json:9: "Brad Crittenden <email address hidden>"
Not using a deliverable email address is preferred.

https://codereview.appspot.com/20170044/diff/1/test/data/browserbundle.json#newcode18
test/data/browserbundle.json:18: "Jorge O. O'Castro
<email address hidden>",
Took the liberty of making Jorge Irish to catch more special characters.

https://codereview.appspot.com/20170044/

Revision history for this message
Richard Harding (rharding) wrote :

code looks ok, comments below. Will QA now.

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js
File app/models/bundle.js (right):

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#newcode75
app/models/bundle.js:75: },
space between functions

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#newcode88
app/models/bundle.js:88: Y.Array.each(changes, function(change) {
if this is an Array, can we just use changes.forEach instead and not
need the YUI module for it?

https://codereview.appspot.com/20170044/diff/1/test/data/browserbundle.json
File test/data/browserbundle.json (right):

https://codereview.appspot.com/20170044/diff/1/test/data/browserbundle.json#newcode18
test/data/browserbundle.json:18: "Jorge O. O'Castro
<email address hidden>",
On 2013/10/31 17:26:28, bac wrote:
> Took the liberty of making Jorge Irish to catch more special
characters.

well played sir

https://codereview.appspot.com/20170044/diff/1/test/test_model_bundle.js
File test/test_model_bundle.js (right):

https://codereview.appspot.com/20170044/diff/1/test/test_model_bundle.js#newcode204
test/test_model_bundle.js:204: var parts = instance.parseNameEmail(
what do you think of naming this more to match the data of
parseAuthorInformation or something?

https://codereview.appspot.com/20170044/

Revision history for this message
Richard Harding (rharding) wrote :

LGTM QA'ok and works with Jorge's bundle now. Thanks for the quick fix!

https://codereview.appspot.com/20170044/

Revision history for this message
Brad Crittenden (bac) wrote :

*** Submitted:

Fix name/email address parsing for commits.

R=rharding
CC=
https://codereview.appspot.com/20170044

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js
File app/models/bundle.js (right):

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#newcode75
app/models/bundle.js:75: },
On 2013/10/31 17:41:09, rharding wrote:
> space between functions

I don't know what you mean here.

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#newcode81
app/models/bundle.js:81: @method extractRecentCommits
On 2013/10/31 17:26:28, bac wrote:
> I see I didn't document the changes arg. Will do so.

Done.

https://codereview.appspot.com/20170044/diff/1/app/models/bundle.js#newcode88
app/models/bundle.js:88: Y.Array.each(changes, function(change) {
On 2013/10/31 17:41:09, rharding wrote:
> if this is an Array, can we just use changes.forEach instead and not
need the
> YUI module for it?

Done.

https://codereview.appspot.com/20170044/diff/1/test/test_model_bundle.js
File test/test_model_bundle.js (right):

https://codereview.appspot.com/20170044/diff/1/test/test_model_bundle.js#newcode204
test/test_model_bundle.js:204: var parts = instance.parseNameEmail(
It seems longer and harder to read and not as obvious. I guess I'm -3.
:)

https://codereview.appspot.com/20170044/

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'app/models/bundle.js'
2--- app/models/bundle.js 2013-10-29 22:51:19 +0000
3+++ app/models/bundle.js 2013-10-31 16:20:30 +0000
4@@ -36,35 +36,6 @@
5 var models = Y.namespace('juju.models');
6
7 /**
8-
9- Extract the recent commits into a format we can use nicely. Output matches
10- the analogous function for charms.
11-
12- @method extractRecentCommits
13- @return {array} Commit objects.
14- */
15- var extractRecentCommits = function(changes) {
16- var commits = [];
17-
18- if (changes) {
19- Y.Array.each(changes, function(change) {
20-
21- var author_parts = /^([\s\w]+?) <(.+)>$/.exec(change.authors[0]);
22- var date = new Date(change.created * 1000);
23- commits.push({
24- author: {
25- name: author_parts[1],
26- email: author_parts[2]
27- },
28- date: date,
29- message: change.message,
30- revno: change.revno
31- });
32- });
33- }
34- return commits;
35- };
36- /**
37 * Model to represent the Bundles from the Charmworld API.
38 *
39 * @class Bundle
40@@ -82,8 +53,55 @@
41 initializer: function(cfg) {
42 this.loaded = false;
43 this.on('load', function() { this.loaded = true; });
44+ },
45+
46+ /**
47+
48+ Parse a combined name-email string of the form
49+ "Full Name <email.example.com>".
50+
51+ Any string that is not parseable has the whole string used as the name
52+ and the email set to 'n/a'.
53+
54+ @method parseNameEmail
55+ @return {array} [name, emailAddress]
56+ */
57+ parseNameEmail: function(author) {
58+ var parts = /^([^<]+?) <(.+)>$/.exec(author);
59+ if (Y.Lang.isNull(parts)) {
60+ parts = [null, author, 'n/a'];
61+ }
62+ return [parts[1], parts[2]];
63+ },
64+ /**
65+
66+ Extract the recent commits into a format we can use nicely. Output matches
67+ the analogous function for charms.
68+
69+ @method extractRecentCommits
70+ @return {array} Commit objects.
71+ */
72+ extractRecentCommits: function(changes) {
73+ var commits = [];
74+
75+ if (changes) {
76+ Y.Array.each(changes, function(change) {
77+
78+ var author_parts = this.parseNameEmail(change.authors[0]);
79+ var date = new Date(change.created * 1000);
80+ commits.push({
81+ author: {
82+ name: author_parts[0],
83+ email: author_parts[1]
84+ },
85+ date: date,
86+ message: change.message,
87+ revno: change.revno
88+ });
89+ }, this);
90+ }
91+ return commits;
92 }
93-
94 }, {
95 /**
96 Static to indicate the type of entity so that other code
97@@ -204,14 +222,14 @@
98 recentCommits: {
99 /**
100 * Return the commits of the charm in a format we can live with from
101- * the source code data provided by the api.
102+ * the source code data provided by the API.
103 *
104 * @method recentCommits.valueFn
105 *
106 */
107 valueFn: function() {
108 var changes = this.get('changes');
109- return extractRecentCommits(changes);
110+ return this.extractRecentCommits(changes);
111 }
112 }
113 }
114
115=== modified file 'test/data/browserbundle.json'
116--- test/data/browserbundle.json 2013-10-29 19:38:27 +0000
117+++ test/data/browserbundle.json 2013-10-31 16:20:30 +0000
118@@ -6,27 +6,28 @@
119 "changes": [
120 {
121 "authors": [
122- "Brad Crittenden <bac@canonical.com>"
123+ "Brad Crittenden <bac@example.com>"
124 ],
125- "committer": "Brad Crittenden <bac@canonical.com>",
126+ "committer": "Brad Crittenden <bac@example.com>",
127 "created": 1378218161.439,
128 "message": "Correct icon",
129 "revno": 3
130 },
131 {
132 "authors": [
133- "Brad Crittenden <bac@canonical.com>"
134+ "Jorge O. O'Castro <jorge@example.com>",
135+ "Brad Crittenden <bac@example.com>"
136 ],
137- "committer": "Brad Crittenden <bac@canonical.com>",
138+ "committer": "Brad Crittenden <bac@example.com>",
139 "created": 1377718535.465,
140 "message": "Added README and icon",
141 "revno": 2
142 },
143 {
144 "authors": [
145- "Brad Crittenden <bac@canonical.com>"
146+ "Brad Crittenden <bac@example.com>"
147 ],
148- "committer": "Brad Crittenden <bac@canonical.com>",
149+ "committer": "Brad Crittenden <bac@example.com>",
150 "created": 1375449744.902,
151 "message": "Initial checking of working config.",
152 "revno": 1
153
154=== modified file 'test/test_model_bundle.js'
155--- test/test_model_bundle.js 2013-10-29 22:51:19 +0000
156+++ test/test_model_bundle.js 2013-10-31 16:20:30 +0000
157@@ -168,7 +168,14 @@
158 instance = new models.Bundle(data);
159 var commits = instance.get('recentCommits');
160 assert.equal('Brad Crittenden', commits[0].author.name);
161- assert.equal('bac@canonical.com', commits[0].author.email);
162+ assert.equal('bac@example.com', commits[0].author.email);
163+ });
164+
165+ it('only the first author is shown', function() {
166+ instance = new models.Bundle(data);
167+ var commits = instance.get('recentCommits');
168+ assert.equal('Jorge O. O\'Castro', commits[1].author.name);
169+ assert.equal('jorge@example.com', commits[1].author.email);
170 });
171
172 it('has the revnos in reverse order', function() {
173@@ -192,4 +199,17 @@
174 assert.equal('Correct icon', commits[0].message);
175 });
176
177+ it('parses full name-email string', function() {
178+ instance = new models.Bundle();
179+ var parts = instance.parseNameEmail(
180+ 'Jorge O. O\'Castro <jcastro@example.com>');
181+ assert.deepEqual(['Jorge O. O\'Castro', 'jcastro@example.com'], parts);
182+ });
183+
184+ it('gracefully handles unparseable name-email', function() {
185+ instance = new models.Bundle();
186+ var parts = instance.parseNameEmail('Jorge O. Castro');
187+ assert.deepEqual(['Jorge O. Castro', 'n/a'], parts);
188+ });
189+
190 });

Subscribers

People subscribed via source and target branches