Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit b509125

Browse files
author
Tilde Ann Thurium
authored
Merge pull request #1906 from atom/tt-19-jan-commit-detail-polish
add committer name to commit detail pane
2 parents dc40e22 + 825e36e commit b509125

File tree

8 files changed

+56
-23
lines changed

8 files changed

+56
-23
lines changed

lib/git-shell-out-strategy.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,13 @@ export default class GitShellOutStrategy {
716716
// %x00 - null byte
717717
// %H - commit SHA
718718
// %ae - author email
719+
// %an = author full name
719720
// %at - timestamp, UNIX timestamp
720721
// %s - subject
721722
// %b - body
722723
const args = [
723724
'log',
724-
'--pretty=format:%H%x00%ae%x00%at%x00%s%x00%b%x00',
725+
'--pretty=format:%H%x00%ae%x00%an%x00%at%x00%s%x00%b%x00',
725726
'--no-abbrev-commit',
726727
'--no-prefix',
727728
'--no-ext-diff',
@@ -751,11 +752,11 @@ export default class GitShellOutStrategy {
751752
const fields = output.trim().split('\0');
752753

753754
const commits = [];
754-
for (let i = 0; i < fields.length; i += 6) {
755-
const body = fields[i + 4].trim();
755+
for (let i = 0; i < fields.length; i += 7) {
756+
const body = fields[i + 5].trim();
756757
let patch = [];
757758
if (includePatch) {
758-
const diffs = fields[i + 5];
759+
const diffs = fields[i + 6];
759760
patch = parseDiff(diffs.trim());
760761
}
761762

@@ -764,8 +765,9 @@ export default class GitShellOutStrategy {
764765
commits.push({
765766
sha: fields[i] && fields[i].trim(),
766767
authorEmail: fields[i + 1] && fields[i + 1].trim(),
767-
authorDate: parseInt(fields[i + 2], 10),
768-
messageSubject: fields[i + 3],
768+
authorName: fields[i + 2] && fields[i + 2].trim(),
769+
authorDate: parseInt(fields[i + 3], 10),
770+
messageSubject: fields[i + 4],
769771
messageBody,
770772
coAuthors,
771773
unbornRef: false,

lib/models/commit.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export default class Commit {
1616
return new Commit({unbornRef: UNBORN});
1717
}
1818

19-
constructor({sha, authorEmail, coAuthors, authorDate, messageSubject, messageBody, unbornRef, patch}) {
19+
constructor({sha, authorEmail, authorName, coAuthors, authorDate, messageSubject, messageBody, unbornRef, patch}) {
2020
this.sha = sha;
2121
this.authorEmail = authorEmail;
22+
this.authorName = authorName;
2223
this.coAuthors = coAuthors || [];
2324
this.authorDate = authorDate;
2425
this.messageSubject = messageSubject;
@@ -36,6 +37,10 @@ export default class Commit {
3637
return this.authorEmail;
3738
}
3839

40+
getAuthorName() {
41+
return this.authorName;
42+
}
43+
3944
getAuthorDate() {
4045
return this.authorDate;
4146
}
@@ -144,7 +149,8 @@ export default class Commit {
144149

145150
isEqual(other) {
146151
// Directly comparable properties
147-
for (const property of ['sha', 'authorEmail', 'authorDate', 'messageSubject', 'messageBody', 'unbornRef']) {
152+
const properties = ['sha', 'authorEmail', 'authorDate', 'messageSubject', 'messageBody', 'unbornRef', 'authorName'];
153+
for (const property of properties) {
148154
if (this[property] !== other[property]) {
149155
return false;
150156
}

lib/views/commit-detail-view.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ export default class CommitDetailView extends React.Component {
131131
const commit = this.props.commit;
132132
const coAuthorCount = commit.getCoAuthors().length;
133133
if (coAuthorCount === 0) {
134-
return commit.getAuthorEmail();
134+
return commit.getAuthorName();
135135
} else if (coAuthorCount === 1) {
136-
return `${commit.getAuthorEmail()} and ${commit.getCoAuthors()[0].email}`;
136+
return `${commit.getAuthorName()} and ${commit.getCoAuthors()[0].name}`;
137137
} else {
138-
return `${commit.getAuthorEmail()} and ${coAuthorCount} others`;
138+
return `${commit.getAuthorName()} and ${coAuthorCount} others`;
139139
}
140140
}
141141

styles/commit-detail.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
&-metaText {
4343
flex: 1;
44-
margin-left: @avatar-dimensions * 1.3; // leave some space for the avatars
44+
margin-left: @avatar-dimensions * 1.4; // leave some space for the avatars
4545
line-height: @avatar-dimensions;
4646
color: @text-color-subtle;
4747
}

test/builder/commit.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class CommitBuilder {
77
constructor() {
88
this._sha = '0123456789abcdefghij0123456789abcdefghij';
99
this._authorEmail = '[email protected]';
10+
this._authorName = 'Tilde Ann Thurium';
1011
this._authorDate = moment('2018-11-28T12:00:00', moment.ISO_8601).unix();
1112
this._coAuthors = [];
1213
this._messageSubject = 'subject';
@@ -25,6 +26,11 @@ class CommitBuilder {
2526
return this;
2627
}
2728

29+
authorName(newName) {
30+
this._authorName = newName;
31+
return this;
32+
}
33+
2834
authorDate(timestamp) {
2935
this._authorDate = timestamp;
3036
return this;
@@ -56,6 +62,7 @@ class CommitBuilder {
5662
const commit = new Commit({
5763
sha: this._sha,
5864
authorEmail: this._authorEmail,
65+
authorName: this._authorName,
5966
authorDate: this._authorDate,
6067
coAuthors: this._coAuthors,
6168
messageSubject: this._messageSubject,

test/git-strategies.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ import * as reporterProxy from '../lib/reporter-proxy';
271271
assert.deepEqual(commits[0], {
272272
sha: '90b17a8e3fa0218f42afc1dd24c9003e285f4a82',
273273
authorEmail: '[email protected]',
274+
authorName: 'Katrina Uychaco',
274275
authorDate: 1471113656,
275276
messageSubject: 'third commit',
276277
messageBody: '',
@@ -281,6 +282,7 @@ import * as reporterProxy from '../lib/reporter-proxy';
281282
assert.deepEqual(commits[1], {
282283
sha: '18920c900bfa6e4844853e7e246607a31c3e2e8c',
283284
authorEmail: '[email protected]',
285+
authorName: 'Katrina Uychaco',
284286
authorDate: 1471113642,
285287
messageSubject: 'second commit',
286288
messageBody: '',
@@ -291,6 +293,7 @@ import * as reporterProxy from '../lib/reporter-proxy';
291293
assert.deepEqual(commits[2], {
292294
sha: '46c0d7179fc4e348c3340ff5e7957b9c7d89c07f',
293295
authorEmail: '[email protected]',
296+
authorName: 'Katrina Uychaco',
294297
authorDate: 1471113625,
295298
messageSubject: 'first commit',
296299
messageBody: '',

test/models/commit.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ describe('Commit', function() {
146146
});
147147
});
148148

149+
it('returns the author name', function() {
150+
const authorName = 'Tilde Ann Thurium';
151+
const commit = commitBuilder().authorName(authorName).build();
152+
assert.strictEqual(commit.getAuthorName(), authorName);
153+
});
154+
149155
describe('isEqual()', function() {
150156
it('returns true when commits are identical', function() {
151157
const a = commitBuilder()
@@ -178,6 +184,13 @@ describe('Commit', function() {
178184
assert.isFalse(a.isEqual(b));
179185
});
180186

187+
it('returns false if author differs', function() {
188+
const a = commitBuilder().authorName('Tilde Ann Thurium').build();
189+
190+
const b = commitBuilder().authorName('Vanessa Yuen').build();
191+
assert.isFalse(a.isEqual(b));
192+
});
193+
181194
it('returns false if a co-author differs', function() {
182195
const a = commitBuilder().addCoAuthor('me', '[email protected]').build();
183196

test/views/commit-detail-view.test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ describe('CommitDetailView', function() {
6262
const commit = commitBuilder()
6363
.sha('420')
6464
.authorEmail('[email protected]')
65+
.authorName('Forthe Win')
6566
.authorDate(moment().subtract(2, 'days').unix())
6667
.messageSubject('subject')
6768
.messageBody('body')
@@ -71,9 +72,9 @@ describe('CommitDetailView', function() {
7172

7273
assert.strictEqual(wrapper.find('.github-CommitDetailView-title').text(), 'subject');
7374
assert.strictEqual(wrapper.find('.github-CommitDetailView-moreText').text(), 'body');
74-
assert.strictEqual(wrapper.find('.github-CommitDetailView-metaText').text(), '[email protected] committed 2 days ago');
75+
assert.strictEqual(wrapper.find('.github-CommitDetailView-metaText').text(), 'Forthe Win committed 2 days ago');
7576
assert.strictEqual(wrapper.find('.github-CommitDetailView-sha').text(), '420');
76-
// assert.strictEqual(wrapper.find('.github-CommitDetailView-sha a').prop('href'), '420');
77+
assert.strictEqual(wrapper.find('.github-CommitDetailView-sha a').prop('href'), 'https://github.com/atom/github/commit/420');
7778
assert.strictEqual(
7879
wrapper.find('img.github-RecentCommit-avatar').prop('src'),
7980
'https://avatars.githubusercontent.com/u/e?email=very%40nice.com&s=32',
@@ -160,33 +161,34 @@ describe('CommitDetailView', function() {
160161
describe('when there are no co-authors', function() {
161162
it('returns only the author', function() {
162163
const commit = commitBuilder()
163-
.authorEmail('[email protected]')
164+
.authorName('Steven Universe')
165+
.authorEmail('[email protected]')
164166
.build();
165167
const wrapper = shallow(buildApp({commit}));
166-
assert.strictEqual(wrapper.instance().getAuthorInfo(), '[email protected]');
168+
assert.strictEqual(wrapper.instance().getAuthorInfo(), 'Steven Universe');
167169
});
168170
});
169171

170172
describe('when there is one co-author', function() {
171173
it('returns author and the co-author', function() {
172174
const commit = commitBuilder()
173-
.authorEmail('[email protected]')
174-
.addCoAuthor('two', '[email protected]')
175+
.authorName('Ruby')
176+
.addCoAuthor('Sapphire', '[email protected]')
175177
.build();
176178
const wrapper = shallow(buildApp({commit}));
177-
assert.strictEqual(wrapper.instance().getAuthorInfo(), '[email protected] and [email protected]');
179+
assert.strictEqual(wrapper.instance().getAuthorInfo(), 'Ruby and Sapphire');
178180
});
179181
});
180182

181183
describe('when there is more than one co-author', function() {
182184
it('returns the author and number of co-authors', function() {
183185
const commit = commitBuilder()
184-
.authorEmail('[email protected]')
185-
.addCoAuthor('two', '[email protected]')
186-
.addCoAuthor('three', '[email protected]')
186+
.authorName('Amethyst')
187+
.addCoAuthor('Peridot', '[email protected]')
188+
.addCoAuthor('Pearl', '[email protected]')
187189
.build();
188190
const wrapper = shallow(buildApp({commit}));
189-
assert.strictEqual(wrapper.instance().getAuthorInfo(), '[email protected] and 2 others');
191+
assert.strictEqual(wrapper.instance().getAuthorInfo(), 'Amethyst and 2 others');
190192
});
191193
});
192194
});

0 commit comments

Comments
 (0)