Skip to content

Commit

Permalink
fix(prepare): update changelog based on commit range (#473)
Browse files Browse the repository at this point in the history
* fix(prepare): ask commit range when tag is missing

* fix: update message

* fix(prepare): update changelog based on commit range

* fix: broken test

* fix: broken test
  • Loading branch information
Eunjae Lee committed Nov 30, 2019
1 parent f659c34 commit 9841f25
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/shipjs/src/flow/prepare.js
Expand Up @@ -72,7 +72,14 @@ async function prepare({
: updateVersion;
await updateVersionFn({ config, nextVersion, releaseType, dir, dryRun });
installDependencies({ config, dir, dryRun });
updateChangelog({ config, firstRelease, releaseCount, dir, dryRun });
updateChangelog({
config,
commitRange,
firstRelease,
releaseCount,
dir,
dryRun,
});
await commitChanges({
nextVersion,
releaseType,
Expand Down
Expand Up @@ -2,6 +2,9 @@ import { run } from '../../../util';
import path from 'path';
import updateChangelog from '../updateChangelog';
jest.mock('path');
jest.mock('temp-write', () => ({
sync: () => '/temp/file/path',
}));

describe('updateChangelog', () => {
it('works', () => {
Expand All @@ -11,14 +14,15 @@ describe('updateChangelog', () => {
updateChangelog: true,
conventionalChangelogArgs: '--foo bar',
},
commitRange: 'abcdefg..HEAD',
firstRelease: false,
releaseCount: 5,
dir: '.',
dryRun: false,
});
expect(run.mock.calls[0][0]).toMatchInlineSnapshot(`
Object {
"command": "/temp/path/conventional-changelog --foo bar -r 5",
"command": "/temp/path/conventional-changelog --foo bar -r 5 -n /temp/file/path",
"dir": ".",
"dryRun": false,
}
Expand Down
15 changes: 14 additions & 1 deletion packages/shipjs/src/step/prepare/updateChangelog.js
@@ -1,19 +1,32 @@
import tempWrite from 'temp-write';
import runStep from '../runStep';
import path from 'path';
import { run } from '../../util';

export default ({ config, firstRelease, releaseCount, dir, dryRun }) =>
export default ({
config,
firstRelease,
releaseCount,
commitRange,
dir,
dryRun,
}) =>
runStep(
{
title: 'Updating the changelog.',
skipIf: () => config.updateChangelog !== true,
},
() => {
const { conventionalChangelogArgs } = config;
const [from, to] = commitRange.split('..');
const tempConfigPath = tempWrite.sync(
`module.exports = { gitRawCommitsOpts: { from: '${from}', to: '${to}' } }`
);
const args = [
conventionalChangelogArgs,
releaseCount ? `-r ${releaseCount}` : undefined,
firstRelease ? '-r 0' : undefined,
`-n ${tempConfigPath}`,
]
.filter(Boolean)
.join(' ');
Expand Down

0 comments on commit 9841f25

Please sign in to comment.