Skip to content

Commit

Permalink
Merge pull request #75 from storybooks/sloppy-option
Browse files Browse the repository at this point in the history
Added --sloppy option
  • Loading branch information
lo1tuma authored May 21, 2017
2 parents e11efce + aad4a93 commit 084c0a3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
build
dist
node_modules
npm-debug.log
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
The main features:

* Writes in a `CHANGELOG.md` from merged GitHub pull requests since the last tag. This works by
* Writes in a `CHANGELOG.md` from merged GitHub pull requests since the last tag. This works by
* first getting a list of all tags
* than removing all tags that are not compatible to [semver versioning](http://semver.org/)
* sort the tags
Expand Down Expand Up @@ -70,9 +70,9 @@ As `pr-log` reads repository information from your project you have to add the `

## Usage

To create or update your changelog run
To create or update your changelog run

```pr-log <version-number>``` where `version-number` is the name of this release
```pr-log [options] <version-number>``` where `version-number` is the name of this release

Example:

Expand All @@ -96,6 +96,12 @@ Given the following setup:
* Fix some spelling mistakes in documentation. (#22)
```

### Options

#### --sloppy

The `--sloppy` option defaults to false. When set, it allows `pr-log` to generate a changelog even when you are not on the `master` branch. This should not be used in production!

### Correct usage makes a clean and complete changelog

If you want your changelog to be complete and clean you have to follow these rules:
Expand Down
6 changes: 5 additions & 1 deletion bin/pr-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import cli from '../cli';

program
.version(config.version)
.option('--sloppy', 'Skip ensuring clean local git state.')
.usage('<version-number>')
.parse(process.argv);

cli.run(program.args[0], program.args[1]).done();
const options = { sloppy: program.sloppy };
cli
.run(program.args[0], options)
.done();
8 changes: 6 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function stripTrailingEmptyLine(text) {
}

export default {
run: (newVersionNumber) => {
run: (newVersionNumber, options) => {
const packageConfig = require(path.join(process.cwd(), 'package.json'));
const githubRepo = getGithubRepo(packageConfig.repository.url);
const changelogPath = path.join(process.cwd(), 'CHANGELOG.md');
Expand All @@ -26,7 +26,11 @@ export default {
throw new Error('version-number not specified');
}

return Promise.try(ensureCleanLocalGitState.bind(null, githubRepo))
const preconditions = options.sloppy ?
Promise.resolve(true) :
Promise.try(ensureCleanLocalGitState.bind(null, githubRepo));

return preconditions
.then(getMergedPullRequests.bind(null, githubRepo))
.then(createChangelog.bind(null, newVersionNumber))
.then(stripTrailingEmptyLine)
Expand Down
21 changes: 19 additions & 2 deletions test/unit/lib/cliSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('CLI', function () {
},
prepend: prependFile
};
const options = { sloppy: false };

const cli = proxyquire('../../../lib/cli', requireStubs).default;

Expand All @@ -31,6 +32,7 @@ describe('CLI', function () {
});

afterEach(function () {
ensureCleanLocalGitState.resolves();
ensureCleanLocalGitState.reset();
getMergedPullRequests.reset();
createChangelog.reset();
Expand All @@ -42,12 +44,27 @@ describe('CLI', function () {
expect(cli.run).to.throw('version-number not specified');
});

it('should throw if the repository is dirty', function () {
ensureCleanLocalGitState.rejects('Local copy is not clean');
expect(cli.run('1.0 ', options)).to.be.rejectedWith('Local copy is not clean');
});

it('should not throw if the repository is dirty', function () {
ensureCleanLocalGitState.rejects('Local copy is not clean');
createChangelog.returns('sloppy changelog');
return cli.run('1.0 ', { sloppy: true })
.then(function () {
expect(prependFile).to.have.been.calledOnce;
expect(prependFile).to.have.been.calledWith('/foo/CHANGELOG.md', 'sloppy changelog');
});
});

it('should report the generated changelog', function () {
const expectedGithubRepo = 'foo/bar';

createChangelog.returns('generated changelog');

return cli.run('1.0.0')
return cli.run('1.0.0', options)
.then(function () {
expect(ensureCleanLocalGitState).to.have.been.calledOnce;
expect(ensureCleanLocalGitState).to.have.been.calledWith(expectedGithubRepo);
Expand All @@ -66,7 +83,7 @@ describe('CLI', function () {
it('should strip trailing empty lines from the generated changelog', function () {
createChangelog.returns('generated\nchangelog\nwith\n\na\nlot\n\nof\nempty\nlines\n\n');

return cli.run('1.0.0')
return cli.run('1.0.0', options)
.then(function () {
expect(prependFile).to.have.been
.calledWith('/foo/CHANGELOG.md', 'generated\nchangelog\nwith\n\na\nlot\n\nof\nempty\nlines\n');
Expand Down

0 comments on commit 084c0a3

Please sign in to comment.