Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shorten commit messages #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/Components/CommitComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ const CommitComponent = ({committedDate, abbreviatedOid, message}) => {

const date = moment(committedDate).fromNow();

function shortenMessage(message) {
message.length > 40 ? message = message.substring(0,37) + "..." : message
return message
};

return (
<div style={{paddingLeft: "1em"}}>
{abbreviatedOid}: {message} ({date})
</div>
<div>
<span>{abbreviatedOid + ": "} </span>
<span>{shortenMessage(message)} </span>
<span>({date})</span>
</div>

)
};

Expand All @@ -20,4 +28,3 @@ CommitComponent.propTypes = {
};

export default CommitComponent;

15 changes: 14 additions & 1 deletion src/Components/__tests__/CommitComponent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React from "react";

const abbreviatedOid = 'AAAAAA';
const message = 'This is a commit message';
const longMessage = 'This is a very long commit message, which will need to be shortened'
const committedDate = '2018-05-04T19:59:54Z';

// Return a fixed timestamp when moment().format() is called
Expand All @@ -19,4 +20,16 @@ it('renders commit correctly', () => {
);
const tree = renderer.getRenderOutput();
expect(tree).toMatchSnapshot();
});
});

it('shortens long commit messages correctly', () => {
const renderer = new ShallowRenderer();
renderer.render(
<CommitComponent
message={longMessage}
abbreviatedOid={abbreviatedOid}
committedDate={committedDate} />
);
const tree = renderer.getRenderOutput();
expect(tree).toMatchSnapshot();
});
45 changes: 32 additions & 13 deletions src/Components/__tests__/__snapshots__/CommitComponent.test.js.snap
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`renders commit correctly 1`] = `
<div
style={
Object {
"paddingLeft": "1em",
}
}
>
AAAAAA
:
This is a commit message
(
3 days ago
)
<div>
<span>
AAAAAA:

</span>
<span>
This is a commit message

</span>
<span>
(
3 days ago
)
</span>
</div>
`;

exports[`shortens long commit messages correctly 1`] = `
<div>
<span>
AAAAAA:

</span>
<span>
This is a very long commit message, w...

</span>
<span>
(
3 days ago
)
</span>
</div>
`;