Skip to content

Commit

Permalink
✨ Group commits by changelog types (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
frinyvonnick authored and bpetetot committed Sep 17, 2018
1 parent 02cec25 commit 7b8b49b
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 104 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"rules": {
"semi": ["error", "never"],
"no-use-before-define": ["error", { "functions": false }],
"comma-dangle": ["error", "always-multiline"],
"no-console": 0
}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ typings/

# next.js build output
.next

CHANGELOG.json
1 change: 0 additions & 1 deletion CHANGELOG.json

This file was deleted.

44 changes: 30 additions & 14 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,47 @@
# Changelog

- Merge branch 'master' into refactor/remove-babel (0e650182544bd4e16cccbdd42e6f1e36b320095c)
- :green_heart: Ignore node_modules in linter (802c0f7dc29508876c6b4d178bbcc8274ee308b5)
- :wrench: missing package.json to update (32e0d943c2b4d06b610b17748486d3cc1e4f3a5a)
- :sparkles: add 'use strict' (4df1b8c92e04902698e13041664642ae16c4c3b4)
- :fire: remove bad property in package.json (dfe9aa9ebaca0003f2a403fee8bdd8d612512dee)
- :wrench: add engines attribute to node 10 in package.json (e93603e071062aac50a126f85121e5ee6ff427aa)
- :recycle: refactor code to native node 10 (1213a06adf517cf57867a1d7c380c5c2e1936b67)
- :wrench: remove .babelrc and change eslint to remove babel parser (379d1854991d4d974a50179f6b72a7e83fa674f9)
- :heavy_minus_sign: remove babel dependencies (f3a2a5cff11d4e0835ae74e70b74acdd8379347b)
## next

### Added

- :sparkles: Add group to commit object (fafbf3635b75ee3f1d0e580976569017025f05b6)
- :sparkles: Use handlebars templating to generate markdown (#10) (141d1601fd1fa3b278db05acbc8f47e2bb239bbf)
- :sparkles: Generate changelog for the next release (#8) (2d783e44e7d4b84a993237e27b95a5d27532426b)
- :sparkles: Implement format option (#5) (9b7287d167637b7a02387cea135d1d7d44a90695)
- :sparkles: Convert changelog to markdown (b165f695f4c1a49ff16a5f03918545bfb36cf367)
- :sparkles: Generate markdown first draft function (10c6d3e20b82f5a0f6ce5cd372899e6519bc2412)
- :tada: Intialize markdown project (a4a12bb4f7133e7e5e40436da4c884f135abf03d)
- :sparkles: Generate changelog JSON file (86ca3eaefb18fd9c9b6bb4256ed2f6fa711aef59)
- :sparkles: Handle when no repository found (c912efd73b9b286711d468ccb73bf1a03bd6f848)
- :package: Fix build (a1526b38e164b8471954e3dd0c658e10595ee966)
- :package: Build dist file (acba6f776196d8312c470ccefce8be81bafd8d52)
- :fire: remove parsing multiple commit (73207b70d85ad2371def0ec9045e5a6ea46fee8c)
- :tada: intialize cli project (0b4f39408e675f368c9562bd7645ac74abcd2293)
- :sparkles: implements changelog generation to json (44e401db08cc828fcc8c19b027350ac9d310773e)
- :truck: move parse functions into parser.js (e29f239dee8dc393caee9d320371e54a37eb90ae)
- :sparkles: add edge cases for commit parsing (cb35644a640cfe3cb2c246345fe25202d814c436)
- :sparkles: Implements parse commit function (195b59431dde83a4cff26be5c3ab362d97a9604e)

### Changed

- :recycle: remove babel to use native node 10 (#3) (6edd0c48591e935f3bcd7e73d48733e623f779d9)
- :truck: move parse functions into parser.js (e29f239dee8dc393caee9d320371e54a37eb90ae)
- :wrench: Fix main script in core module (7f091a3900605ee9bc44e793ddbb10a7272112fa)
- :wrench: Add build script (efbc04d902ac201b128a8e02692b778eff109b12)
- :wrench: Add lint (9faf008d457d777afe0fa3443c34af510c1098fa)
- :green_heart: Set up travis configuration (dda9b287989c1ca2e9513c4a5a4a3d1b6749e816)
- :wrench: Set up tests (656c8bbb506fc8f9064df1fc7aa64e2f1869751e)
- :wrench: Add package.json (34c8f53a58487a6368016de09989465cd2a96786)

### Removed

- :fire: remove parsing multiple commit (73207b70d85ad2371def0ec9045e5a6ea46fee8c)

### Fixed

- :green_heart: Ignore node_modules in linter (802c0f7dc29508876c6b4d178bbcc8274ee308b5)
- :green_heart: Set up travis configuration (dda9b287989c1ca2e9513c4a5a4a3d1b6749e816)

### Miscellaneous

- :memo: Add README.md (c177349386dfd87ab41c58f8a317b0962a511207)
- :package: Fix build (a1526b38e164b8471954e3dd0c658e10595ee966)
- :package: Build dist file (acba6f776196d8312c470ccefce8be81bafd8d52)
- Initial commit (a60d98def5bcbbef74a19db9e8f43af7a6ff6865)


17 changes: 15 additions & 2 deletions packages/gitmoji-changelog-core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const concat = require('concat-stream')
const { promisify } = require('util')

const { parseCommit } = require('./parser')
const mapping = require('./mapping')

const gitSemverTagsAsync = promisify(gitSemverTags)

Expand All @@ -24,22 +25,34 @@ function getCommits(from, to) {
})
}

function makeGroups(commits) {
return mapping
.map(({ group, label }) => ({
group,
label,
commits: commits.filter(commit => commit.group === group),
}))
.filter(group => group.commits.length)
}

async function generateChangelog() {
let previousTag = ''
const tags = await gitSemverTagsAsync()

const result = await Promise.all(tags.map(async tag => {
const commits = await getCommits(previousTag, tag)

previousTag = tag
return {
version: tag,
commits,
groups: makeGroups(commits),
}
}))

const commits = await getCommits(previousTag)
result.push({
version: 'next',
commits: await getCommits(previousTag),
groups: makeGroups(commits),
})

return result
Expand Down
105 changes: 64 additions & 41 deletions packages/gitmoji-changelog-core/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,23 @@ const gitSemverTags = require('git-semver-tags')

const { generateChangelog } = require('./index')

const sparklesCommit = {
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23f',
date: '2018-08-28T10:06:00+02:00',
subject: ':sparkles: Upgrade brand new feature',
body: 'Waouh this is awesome 2',
}

const recycleCommit = {
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23c',
date: '2018-08-28T10:07:00+02:00',
subject: ':recycle: Upgrade brand new feature',
body: 'Waouh this is awesome 3',
}

describe('changelog', () => {
beforeEach(() => {
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
readable.push(`
c40ee8669ba7ea5151adc2942fa8a7fc98d9e23c
2018-08-28T10:07:00+02:00
:sparkles: Upgrade brand new feature
Waouh this is awesome 3
`)
readable.push(null)
readable.emit('close')
return readable
})
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
readable.push(`
c40ee8669ba7ea5151adc2942fa8a7fc98d9e23f
2018-08-28T10:06:00+02:00
:sparkles: Upgrade brand new feature
Waouh this is awesome 2
`)
readable.push(null)
readable.emit('close')
return readable
})
mockCommits()
})

it('should generate changelog in json format for next release', async () => {
Expand All @@ -42,12 +31,13 @@ Waouh this is awesome 2
expect(result).toEqual([
{
version: 'next',
commits: [
groups: [
{
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23c',
date: '2018-08-28T10:07:00+02:00',
subject: ':sparkles: Upgrade brand new feature',
body: 'Waouh this is awesome 3',
group: 'changed',
label: 'Changed',
commits: [
expect.objectContaining(recycleCommit),
],
},
],
},
Expand All @@ -62,23 +52,25 @@ Waouh this is awesome 2
expect(result).toEqual([
{
version: 'v1.0.0',
commits: [
groups: [
{
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23f',
date: '2018-08-28T10:06:00+02:00',
subject: ':sparkles: Upgrade brand new feature',
body: 'Waouh this is awesome 2',
group: 'added',
label: 'Added',
commits: [
expect.objectContaining(sparklesCommit),
],
},
],
},
{
version: 'next',
commits: [
groups: [
{
hash: 'c40ee8669ba7ea5151adc2942fa8a7fc98d9e23c',
date: '2018-08-28T10:07:00+02:00',
subject: ':sparkles: Upgrade brand new feature',
body: 'Waouh this is awesome 3',
group: 'changed',
label: 'Changed',
commits: [
expect.objectContaining(recycleCommit),
],
},
],
},
Expand All @@ -88,3 +80,34 @@ Waouh this is awesome 2

jest.mock('git-raw-commits')
jest.mock('git-semver-tags')

function mockCommits() {
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
const {
hash,
date,
subject,
body,
} = recycleCommit
readable.push(`\n${hash}\n${date}\n${subject}\n${body}\n`)
readable.push(null)
readable.emit('close')
return readable
})
gitRawCommits.mockImplementationOnce(() => {
const stream = require('stream')
const readable = new stream.Readable()
const {
hash,
date,
subject,
body,
} = sparklesCommit
readable.push(`\n${hash}\n${date}\n${subject}\n${body}\n`)
readable.push(null)
readable.emit('close')
return readable
})
}
77 changes: 77 additions & 0 deletions packages/gitmoji-changelog-core/src/mapping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
module.exports = [
{
group: 'added',
label: 'Added',
emojis: [
'sparkles',
'tada',
'white_check_mark',
'bookmark',
'construction_worker',
'charts_with_upwards_trend',
'heavy_plus_sign',
'loud_sound',
],
},
{
group: 'changed',
label: 'Changed',
emojis: [
'art',
'zap',
'lipstick',
'rotating_light',
'arrow_down',
'arrow_up',
'pushpin',
'recycle',
'wrench',
'rewind',
'alien',
'truck',
'boom',
'bento',
'wheelchair',
'speech_ballon',
'card_file_box',
'children_crossing',
'building_construction',
'iphone',
],
},
{
group: 'deprecated',
label: 'Deprecated',
emojis: [],
},
{
group: 'removed',
label: 'Removed',
emojis: ['fire', 'heavy_minus_sign', 'mute'],
},
{
group: 'fixed',
label: 'Fixed',
emojis: [
'bug',
'ambulance',
'apple',
'penguin',
'checkered_flag',
'robot',
'green_apple',
'green_heart',
'pencil2',
],
},
{
group: 'security',
label: 'Security',
emojis: ['lock'],
},
{
group: 'misc',
label: 'Miscellaneous',
emojis: [],
},
]
31 changes: 31 additions & 0 deletions packages/gitmoji-changelog-core/src/parser.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
const splitLines = require('split-lines')
const mapping = require('./mapping')

function parseSubject(subject) {
if (!subject) return {}
const matches = subject.match(/:(\w*):(.*)/)
if (!matches) return {}
const [, emoji, message] = matches

return {
emoji,
message: message.trim(),
}
}

function getCommitGroup(emoji) {
let group = 'misc'

mapping.forEach(type => {
if (type.emojis.includes(emoji)) {
group = type.group
}
})

return group
}

function parseCommit(commit) {
const lines = splitLines(commit)
const [hash, date, subject, ...body] = lines.splice(1, lines.length - 2)
const { emoji, message } = parseSubject(subject)
const group = getCommitGroup(emoji)

return {
hash,
date,
subject,
emoji,
message,
group,
body: body.join('\n'),
}
}

module.exports = {
parseCommit,
getCommitGroup,
}
Loading

0 comments on commit 7b8b49b

Please sign in to comment.