Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
14 changes: 8 additions & 6 deletions lib/git-shell-out-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,12 +716,13 @@ export default class GitShellOutStrategy {
// %x00 - null byte
// %H - commit SHA
// %ae - author email
// %an = author full name
// %at - timestamp, UNIX timestamp
// %s - subject
// %b - body
const args = [
'log',
'--pretty=format:%H%x00%ae%x00%at%x00%s%x00%b%x00',
'--pretty=format:%H%x00%ae%x00%an%x00%at%x00%s%x00%b%x00',
'--no-abbrev-commit',
'--no-prefix',
'--no-ext-diff',
Expand Down Expand Up @@ -751,11 +752,11 @@ export default class GitShellOutStrategy {
const fields = output.trim().split('\0');

const commits = [];
for (let i = 0; i < fields.length; i += 6) {
const body = fields[i + 4].trim();
for (let i = 0; i < fields.length; i += 7) {
const body = fields[i + 5].trim();
let patch = [];
if (includePatch) {
const diffs = fields[i + 5];
const diffs = fields[i + 6];
patch = parseDiff(diffs.trim());
}

Expand All @@ -764,8 +765,9 @@ export default class GitShellOutStrategy {
commits.push({
sha: fields[i] && fields[i].trim(),
authorEmail: fields[i + 1] && fields[i + 1].trim(),
authorDate: parseInt(fields[i + 2], 10),
messageSubject: fields[i + 3],
authorName: fields[i + 2] && fields[i + 2].trim(),
authorDate: parseInt(fields[i + 3], 10),
messageSubject: fields[i + 4],
messageBody,
coAuthors,
unbornRef: false,
Expand Down
10 changes: 8 additions & 2 deletions lib/models/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ export default class Commit {
return new Commit({unbornRef: UNBORN});
}

constructor({sha, authorEmail, coAuthors, authorDate, messageSubject, messageBody, unbornRef, patch}) {
constructor({sha, authorEmail, authorName, coAuthors, authorDate, messageSubject, messageBody, unbornRef, patch}) {
this.sha = sha;
this.authorEmail = authorEmail;
this.authorName = authorName;
this.coAuthors = coAuthors || [];
this.authorDate = authorDate;
this.messageSubject = messageSubject;
Expand All @@ -36,6 +37,10 @@ export default class Commit {
return this.authorEmail;
}

getAuthorName() {
return this.authorName;
}

getAuthorDate() {
return this.authorDate;
}
Expand Down Expand Up @@ -144,7 +149,8 @@ export default class Commit {

isEqual(other) {
// Directly comparable properties
for (const property of ['sha', 'authorEmail', 'authorDate', 'messageSubject', 'messageBody', 'unbornRef']) {
const properties = ['sha', 'authorEmail', 'authorDate', 'messageSubject', 'messageBody', 'unbornRef', 'authorName'];
for (const property of properties) {
if (this[property] !== other[property]) {
return false;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/views/commit-detail-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ export default class CommitDetailView extends React.Component {
const commit = this.props.commit;
const coAuthorCount = commit.getCoAuthors().length;
if (coAuthorCount === 0) {
return commit.getAuthorEmail();
return commit.getAuthorName();
} else if (coAuthorCount === 1) {
return `${commit.getAuthorEmail()} and ${commit.getCoAuthors()[0].email}`;
return `${commit.getAuthorName()} and ${commit.getCoAuthors()[0].name}`;
} else {
return `${commit.getAuthorEmail()} and ${coAuthorCount} others`;
return `${commit.getAuthorName()} and ${coAuthorCount} others`;
}
}

Expand Down
2 changes: 1 addition & 1 deletion styles/commit-detail.less
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

&-metaText {
flex: 1;
margin-left: @avatar-dimensions * 1.3; // leave some space for the avatars
margin-left: @avatar-dimensions * 1.4; // leave some space for the avatars
line-height: @avatar-dimensions;
color: @text-color-subtle;
}
Expand Down
7 changes: 7 additions & 0 deletions test/builder/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class CommitBuilder {
constructor() {
this._sha = '0123456789abcdefghij0123456789abcdefghij';
this._authorEmail = '[email protected]';
this._authorName = 'Tilde Ann Thurium';
this._authorDate = moment('2018-11-28T12:00:00', moment.ISO_8601).unix();
this._coAuthors = [];
this._messageSubject = 'subject';
Expand All @@ -25,6 +26,11 @@ class CommitBuilder {
return this;
}

authorName(newName) {
this._authorName = newName;
return this;
}

authorDate(timestamp) {
this._authorDate = timestamp;
return this;
Expand Down Expand Up @@ -56,6 +62,7 @@ class CommitBuilder {
const commit = new Commit({
sha: this._sha,
authorEmail: this._authorEmail,
authorName: this._authorName,
authorDate: this._authorDate,
coAuthors: this._coAuthors,
messageSubject: this._messageSubject,
Expand Down
3 changes: 3 additions & 0 deletions test/git-strategies.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ import * as reporterProxy from '../lib/reporter-proxy';
assert.deepEqual(commits[0], {
sha: '90b17a8e3fa0218f42afc1dd24c9003e285f4a82',
authorEmail: '[email protected]',
authorName: 'Katrina Uychaco',
authorDate: 1471113656,
messageSubject: 'third commit',
messageBody: '',
Expand All @@ -281,6 +282,7 @@ import * as reporterProxy from '../lib/reporter-proxy';
assert.deepEqual(commits[1], {
sha: '18920c900bfa6e4844853e7e246607a31c3e2e8c',
authorEmail: '[email protected]',
authorName: 'Katrina Uychaco',
authorDate: 1471113642,
messageSubject: 'second commit',
messageBody: '',
Expand All @@ -291,6 +293,7 @@ import * as reporterProxy from '../lib/reporter-proxy';
assert.deepEqual(commits[2], {
sha: '46c0d7179fc4e348c3340ff5e7957b9c7d89c07f',
authorEmail: '[email protected]',
authorName: 'Katrina Uychaco',
authorDate: 1471113625,
messageSubject: 'first commit',
messageBody: '',
Expand Down
13 changes: 13 additions & 0 deletions test/models/commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ describe('Commit', function() {
});
});

it('returns the author name', function() {
const authorName = 'Tilde Ann Thurium';
const commit = commitBuilder().authorName(authorName).build();
assert.strictEqual(commit.getAuthorName(), authorName);
});

describe('isEqual()', function() {
it('returns true when commits are identical', function() {
const a = commitBuilder()
Expand Down Expand Up @@ -178,6 +184,13 @@ describe('Commit', function() {
assert.isFalse(a.isEqual(b));
});

it('returns false if author differs', function() {
const a = commitBuilder().authorName('Tilde Ann Thurium').build();

const b = commitBuilder().authorName('Vanessa Yuen').build();
assert.isFalse(a.isEqual(b));
});

it('returns false if a co-author differs', function() {
const a = commitBuilder().addCoAuthor('me', '[email protected]').build();

Expand Down
24 changes: 13 additions & 11 deletions test/views/commit-detail-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ describe('CommitDetailView', function() {
const commit = commitBuilder()
.sha('420')
.authorEmail('[email protected]')
.authorName('Forthe Win')
.authorDate(moment().subtract(2, 'days').unix())
.messageSubject('subject')
.messageBody('body')
Expand All @@ -71,9 +72,9 @@ describe('CommitDetailView', function() {

assert.strictEqual(wrapper.find('.github-CommitDetailView-title').text(), 'subject');
assert.strictEqual(wrapper.find('.github-CommitDetailView-moreText').text(), 'body');
assert.strictEqual(wrapper.find('.github-CommitDetailView-metaText').text(), '[email protected] committed 2 days ago');
assert.strictEqual(wrapper.find('.github-CommitDetailView-metaText').text(), 'Forthe Win committed 2 days ago');
assert.strictEqual(wrapper.find('.github-CommitDetailView-sha').text(), '420');
// assert.strictEqual(wrapper.find('.github-CommitDetailView-sha a').prop('href'), '420');
assert.strictEqual(wrapper.find('.github-CommitDetailView-sha a').prop('href'), 'https://github.com/atom/github/commit/420');
assert.strictEqual(
wrapper.find('img.github-RecentCommit-avatar').prop('src'),
'https://avatars.githubusercontent.com/u/e?email=very%40nice.com&s=32',
Expand Down Expand Up @@ -160,33 +161,34 @@ describe('CommitDetailView', function() {
describe('when there are no co-authors', function() {
it('returns only the author', function() {
const commit = commitBuilder()
.authorEmail('[email protected]')
.authorName('Steven Universe')
.authorEmail('[email protected]')
.build();
const wrapper = shallow(buildApp({commit}));
assert.strictEqual(wrapper.instance().getAuthorInfo(), '[email protected]');
assert.strictEqual(wrapper.instance().getAuthorInfo(), 'Steven Universe');
});
});

describe('when there is one co-author', function() {
it('returns author and the co-author', function() {
const commit = commitBuilder()
.authorEmail('[email protected]')
.addCoAuthor('two', '[email protected]')
.authorName('Ruby')
.addCoAuthor('Sapphire', '[email protected]')
.build();
const wrapper = shallow(buildApp({commit}));
assert.strictEqual(wrapper.instance().getAuthorInfo(), '[email protected] and [email protected]');
assert.strictEqual(wrapper.instance().getAuthorInfo(), 'Ruby and Sapphire');
});
});

describe('when there is more than one co-author', function() {
it('returns the author and number of co-authors', function() {
const commit = commitBuilder()
.authorEmail('[email protected]')
.addCoAuthor('two', '[email protected]')
.addCoAuthor('three', '[email protected]')
.authorName('Amethyst')
.addCoAuthor('Peridot', '[email protected]')
.addCoAuthor('Pearl', '[email protected]')
.build();
const wrapper = shallow(buildApp({commit}));
assert.strictEqual(wrapper.instance().getAuthorInfo(), '[email protected] and 2 others');
assert.strictEqual(wrapper.instance().getAuthorInfo(), 'Amethyst and 2 others');
});
});
});
Expand Down