improve changelog (#5777)

This commit is contained in:
Pooya Parsa 2019-05-21 23:40:15 +04:30 committed by Xin Du (Clark)
parent ac06cbef51
commit 8a490d62ca

View File

@ -6,14 +6,13 @@ import uniq from 'lodash/uniq'
import { writeFile } from 'fs-extra' import { writeFile } from 'fs-extra'
const types = { const types = {
fix: { title: 'Fixes' }, fix: { title: '🐛 Bug Fix' },
feat: { title: 'Features' }, feat: { title: '🚀 Features' },
hotfix: { title: 'HotFixes' }, refactor: { title: '💅 Refactors' },
refactor: { title: 'Refactors' }, perf: { title: '🔥 Performance' },
perf: { title: 'Performance Improvements' }, examples: { title: '📝 Examples' },
examples: { title: 'Examples' }, chore: { title: '🏡 Chore' },
chore: { title: 'Chore' }, test: { title: '👓 Tests' }
test: { title: 'Tests' }
} }
const knownAuthors = [ const knownAuthors = [
@ -88,6 +87,7 @@ function parseCommits(commits) {
message = message.join(':') message = message.join(':')
// Extract references from message // Extract references from message
message = message.replace(/\((fixes) #\d+\)/g, '')
const references = [] const references = []
const referencesRegex = /#[0-9]+/g const referencesRegex = /#[0-9]+/g
let m let m
@ -103,6 +103,9 @@ function parseCommits(commits) {
if (scope) { if (scope) {
scope = scope[1] scope = scope[1]
} }
if (!scope) {
scope = 'general'
}
type = type.split('(')[0] type = type.split('(')[0]
return { return {
@ -116,38 +119,35 @@ function parseCommits(commits) {
} }
function generateMarkDown(commits) { function generateMarkDown(commits) {
const commitGroups = groupBy(commits, 'type') const typeGroups = groupBy(commits, 'type')
let markdown = '' let markdown = ''
for (const type of allowedTypes) { for (const type of allowedTypes) {
const group = commitGroups[type] const group = typeGroups[type]
if (!group || !group.length) { if (!group || !group.length) {
continue continue
} }
const { title } = types[type] const { title } = types[type]
markdown += '\n\n' + '## ' + title + '\n\n' markdown += '\n\n' + '#### ' + title + '\n\n'
markdown += sortBy(group, 'scope').map(formatCommitForMarkdown).join('\n')
const scopeGroups = groupBy(group, 'scope')
for (const scopeName in scopeGroups) {
markdown += '- `' + scopeName + '`' + '\n'
for (const commit of scopeGroups[scopeName]) {
markdown += ' - ' + commit.references.join(',') + ' ' + commit.message + '\n'
}
}
} }
const authors = sortBy(uniq(commits.map(commit => commit.authorName).filter(an => !isKnownAuthor(an)))) const authors = sortBy(uniq(commits.map(commit => commit.authorName).filter(an => !isKnownAuthor(an))))
if (authors.length) { if (authors.length) {
markdown += '\n\n' + '## ' + 'Thanks to' + '\n\n' markdown += '\n\n' + '#### ' + '💖 Thanks to' + '\n\n'
markdown += authors.map(name => '- ' + name).join('\n') markdown += authors.map(name => '- ' + name).join('\n')
} }
return markdown.trim() return markdown.trim()
} }
function formatCommitForMarkdown({ scope, type, message, references }) {
let fMessage = scope ? `**${scope}**: ${message}` : message
if (references.length) {
fMessage += ' ' + references.map(r => `(${r})`).join(' ')
}
return '- ' + fMessage
}
main().catch(consola.error) main().catch(consola.error)