Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
feat(stream): emmit an empty string to down stream if commit cannot b…
Browse files Browse the repository at this point in the history
…e parsed

This makes it possible for down stream to know if one commit cannot be parsed.`

BREAKING CHANGE: It no longer skips the chunk if commit cannot be parsed. An empty string is passed to down stream
  • Loading branch information
stevemao committed Mar 9, 2015
1 parent b6640b3 commit f184310
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ stream

### conventionalCommitsParser([options])

Returns an object stream.
Returns an object stream. If there is any malformed commits it will be gracefully ignored (an empty data will be emitted so down stream can notice).

#### options

Expand Down
6 changes: 5 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ if (length > 0) {
stream.pipe(conventionalCommitsParser(cli.flags))
.pipe(JSONStream.stringify('', '', ''))
.pipe(through(function(chunk, enc, cb) {
cb(null, 'result: ' + chunk + '\n\n');
if (chunk.toString() === '""') {
cb(null, 'Commit cannot be parsed\n\n');
} else {
cb(null, 'Result: ' + chunk + '\n\n');
}
}))
.pipe(process.stdout);

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function conventionalCommitsParser(options) {
if (commit) {
cb(null, commit);
} else {
cb();
cb(null, '');
}
});
}
Expand Down
7 changes: 4 additions & 3 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ describe('conventionalCommitsParser', function() {
stream
.pipe(conventionalCommitsParser())
.pipe(through.obj(function(chunk, enc, cb) {
expect(chunk.hash).to.equal('13f31602f396bc269076ab4d389cfd8ca94b20ba');
i++;
if (++i !== 2) {
expect(chunk.hash).to.equal('13f31602f396bc269076ab4d389cfd8ca94b20ba');
}
cb();
}, function() {
expect(i).to.equal(2);
expect(i).to.equal(3);
done();
}));
});
Expand Down

0 comments on commit f184310

Please sign in to comment.