diff --git a/cli.js b/cli.js index 7d049eb..609ef74 100755 --- a/cli.js +++ b/cli.js @@ -42,7 +42,7 @@ function processFile(fileIndex) { fs.createReadStream(filePath) .on('error', function(err) { console.warn('Failed to read file ' + filePath + '\n' + err); - if(++fileIndex < length) { + if (++fileIndex < length) { processFile(fileIndex); } }) @@ -50,7 +50,7 @@ function processFile(fileIndex) { .pipe(conventionalCommitsParser(cli.flags)) .pipe(JSONStream.stringify()) .on('end', function() { - if(++fileIndex < length) { + if (++fileIndex < length) { processFile(fileIndex); } }) diff --git a/lib/parser.js b/lib/parser.js index 4838b3e..f285e05 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -26,6 +26,10 @@ function parser(raw, options) { lines.splice(0, 2); } + if (!msg.header) { + return null; + } + match = msg.header.match(options.headerPattern); if (!match || !match[1] || !match[3]) { return null; diff --git a/test/parser.spec.js b/test/parser.spec.js index 2329ad3..725dd7b 100644 --- a/test/parser.spec.js +++ b/test/parser.spec.js @@ -51,6 +51,10 @@ describe('parseRawCommit', function() { expect(parser('bla bla', options)).to.equal(null); }); + it('should returns null if there is no header', function() { + expect(parser('056f5827de86cace1f282c8e3f1cccc952fcad2e', options)).to.equal(null); + }); + it('should parse header', function() { expect(msg.header).to.equal('feat(scope): broadcast $destroy event on scope destruction'); });