Skip to content

Commit

Permalink
feat(changelog): set emoji to changelog commits. Fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Richter committed Jul 31, 2020
1 parent 79aef6f commit 9ce6d8e
Show file tree
Hide file tree
Showing 3 changed files with 277 additions and 123 deletions.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,41 @@ anything in `node_modules`.
* `deprecated`: String (may be empty) describing reason this package has been
deprecated. To deprecate a package, set it to a descriptive reason.
To "un-deprecate" a package, set it to an empty string (can then be later deleted).
* `emoji`:
Configure changelog emoji setting logic
* `emoji.skip`: deactivates emoji in changelog. Default: `null`
* `emoji.set`: Custom emojis map, which will overwrite the default one

Example for
```json5
{
"nlm": {
"emoji": {
"set": {
"refactor": "🔥" // will overwrite the existing setting for "refactor" type
}
}
}
}
```

The default emojis for the commit types are:
```json5
{
"feat": "",
"fix": "🐛",
"perf": "",
"refactor": "📦️",
"chore": "♻️",
"build": "👷",
"revert": "↩️",
"docs": "📝",
"style": "🎨",
"test": "",
"ci": "💚",
"breaking": "💥" // this emoji will be set before the "Breaking Change" section
}
```

If there's no file named `LICENSE` in the repository, `nlm` won't attempt to add the headers.

Expand Down
49 changes: 38 additions & 11 deletions lib/steps/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ const Github = require('../github/client');

const parseRepository = require('../github/parse-repository');

const emojiMaps = new Map([
[
'default',
{
breaking: '💥',
feat: '✨',
fix: '🐛',
perf: '⚡',
refactor: '📦️',
chore: '♻️',
build: '👷',
revert: '↩️',
docs: '📝',
style: '🎨',
test: '✅',
ci: '💚',
},
],
]);

function addPullRequestCommits(pkg, commits, pr) {
const github = Github.forRepository(pkg.repository);
return Promise.all([
Expand Down Expand Up @@ -92,11 +112,16 @@ function removeInvalidPRs(prs) {
});
prs.length = filtered.length;
Object.assign(prs, filtered);
return { ...prs, ...filtered, length: filtered.length };
}

async function generateChangeLog(cwd, pkg, options) {
const repoInfo = parseRepository(pkg.repository);
const { commits } = options;
const { commits, emoji = {} } = options;
let emojiSet = {};
if (!emoji.skip) {
emojiSet = { ...emojiMaps.get('default'), ...(emoji.set || {}) };
}
const prs = commits.filter(c => c.type === 'pr');

function getCommitLink(commit) {
Expand All @@ -118,15 +143,15 @@ async function generateChangeLog(cwd, pkg, options) {
function prependBreakingChanges(changelog) {
const breaking = flatten(commits.map(extractBreakingChanges));
if (!breaking.length) return changelog;
return [
'#### Breaking Changes',
'',
breaking.map(formatBreakingChange).join('\n\n'),
'',
'#### Commits',
'',
changelog,
].join('\n');
return `#### ${
!emoji.skip ? `${emojiSet['breaking']} ` : ''
}Breaking Changes
${breaking.map(formatBreakingChange).join('\n\n')}
#### Commits
${changelog}`;
}

function formatReference(ref) {
Expand All @@ -142,7 +167,9 @@ async function generateChangeLog(cwd, pkg, options) {
let subject;

if (commit.type) {
subject = `**${commit.type}:** ${commit.subject}`;
subject = `${!emoji.skip ? `${emojiSet[commit.type]} ` : ''}**${
commit.type
}:** ${commit.subject}`;
} else {
subject = commit.header;
}
Expand Down
Loading

0 comments on commit 9ce6d8e

Please sign in to comment.