Skip to content

Commit

Permalink
[Code] Commit component rework (elastic#46097)
Browse files Browse the repository at this point in the history
* Remove unnecessary whitespace

* Split CommitHistory into multiple files

There were already >5 components in this file; this splits them into
smaller, distinct components/files and an index.

* Extract props to interfaces

Rather than keeping them inline.

* Add basic implementation of new commit actions

This is embedded within the Commit component, for now.

Obviates CommitLink for now, but we'll address that in the PR.

* Update the remainder of the Commit layout

* Parses and displays the commit title/description
* Parses and displays the author and date
* Adds new translations

* Update translation keys to match naming standards

See
https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/GUIDELINE.md
for details.

* Extract commit message parsing to helper util

* Move CommitLink to commit folder

* Fix font-sizes of commit text

I was reading the wrong field in figma. Whoops!

* Add RepoLink component controlled by a boolean

If we're already viewing the commit in the context of the repo, the link
here isn't as helpful. For our first use, the commit history, that is
the case.

* Simpler construction of app paths

We should build a helper for this, but these are strewn about the
codebase.

* Update snapshots following text size changes

* Truncate summary text

* Fix type error on test component

* Make date-dependent test timezone-agnostic

Uses Date.UTC to get a non-relative date/time.
  • Loading branch information
rylnd committed Sep 30, 2019
1 parent c05b383 commit 519de2a
Show file tree
Hide file tree
Showing 13 changed files with 531 additions and 90 deletions.
33 changes: 33 additions & 0 deletions x-pack/legacy/plugins/code/common/commit_utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { parseCommitMessage } from './commit_utils';

describe('Commit Utils', () => {
describe('parseCommitMessage', () => {
it('parses the summary from a commit message', () => {
const message = "This is a summary\n\nAnd here's the body";
const { summary } = parseCommitMessage(message);

expect(summary).toEqual('This is a summary');
});

it('parses the body from a commit message', () => {
const message = "This is a summary\n\nAnd here's the body";
const { body } = parseCommitMessage(message);

expect(body).toEqual("And here's the body");
});

it('includes the second line as body, if erroneously present', () => {
const messageWithSecondLine = 'summary\nsecond\ndescription';
const { summary, body } = parseCommitMessage(messageWithSecondLine);

expect(summary).toEqual('summary');
expect(body).toEqual('second\ndescription');
});
});
});
14 changes: 14 additions & 0 deletions x-pack/legacy/plugins/code/common/commit_utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

const parseCommitMessage: (message: string) => { summary: string; body: string } = message => {
const [summary, ...rest] = message.split('\n');
const body = rest.join('\n').trim();

return { summary, body };
};

export { parseCommitMessage };

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { mount } from 'enzyme';
import toJson from 'enzyme-to-json';

import { Commit } from './commit';
import { CommitInfo } from '../../../model/commit';

describe('Commit component', () => {
test('renders correctly for a commit', () => {
const commitInfo: CommitInfo = {
updated: new Date(Date.UTC(2222, 10, 11)),
message: 'This is my commit message\n\nThis is the description',
author: 'author',
committer: 'committer',
id: '4ba67b8',
parents: ['9817575'],
treeId: '96440ceb55e04a99d33c1c8ee021400a680fbf74',
};
const wrapper = mount(
<Commit
showRepoLink={false}
commit={commitInfo}
date="11/11/2222"
repoUri="github.com/elastic/code"
/>
);

expect(toJson(wrapper)).toMatchSnapshot();
});
});
Loading

0 comments on commit 519de2a

Please sign in to comment.