Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

conventional-commits-parser

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conventional-commits-parser - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

CHANGELOG.md

31

lib/parser.js

@@ -33,3 +33,3 @@ 'use strict';

var otherFields = {};
var lines = _.compact(raw.split('\n'));
var lines = raw.trim().split('\n');
var continueNote = false;

@@ -48,4 +48,2 @@ var isBody = true;

raw = lines.join('\n');
// msg parts

@@ -95,4 +93,5 @@ var header = lines.shift();

repository: repository,
issue: referenceMatch[2],
raw: referenceMatch[0]
issue: referenceMatch[3],
raw: referenceMatch[0],
prefix: referenceMatch[2]
};

@@ -166,4 +165,5 @@ references.push(reference);

repository: repository,
issue: referenceMatch[2],
raw: referenceMatch[0]
issue: referenceMatch[3],
raw: referenceMatch[0],
prefix: referenceMatch[2]
};

@@ -199,9 +199,2 @@ references.push(reference);

if (!body) {
body = null;
}
if (!footer) {
footer = null;
}
// does this commit revert any other commit?

@@ -220,6 +213,12 @@ revertMatch = raw.match(options.revertPattern);

_.map(notes, function(note) {
note.text = note.text.trim();
return note;
});
var msg = _.merge(headerParts, {
header: header,
body: body,
footer: footer,
body: body ? body.trim() : null,
footer: footer ? footer.trim() : null,
notes: notes,

@@ -226,0 +225,0 @@ references: references,

@@ -29,3 +29,3 @@ 'use strict';

return new RegExp('(?:.*?)??\\s*(\\S*?)??(?:' + join(issuePrefixes, '|') + ')(\\d+)', 'gi');
return new RegExp('(?:.*?)??\\s*(\\S*?)??(' + join(issuePrefixes, '|') + ')(\\d+)', 'gi');
}

@@ -32,0 +32,0 @@

{
"name": "conventional-commits-parser",
"version": "0.1.0",
"version": "0.1.1",
"description": "Parse raw conventional commits",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/stevemao/conventional-commits-parser",

@@ -6,10 +6,7 @@ # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url]

Adapted from code originally written by @ajoslin in [conventional-changelog](https://github.com/ajoslin/conventional-changelog).
## Conventional Commit Message Format
A minimum input should contain the raw message.
A minimum input should contain a raw message.
Each commit message consists of a a **header**, a **body** (optional) and a **footer** (optional).
Each commit message consists of a a **header** (mandatory), a **body** and a **footer**.

@@ -39,4 +36,6 @@ ```

This module will just parse the message itself. However, it is possible to include other fields such as hash, committer or date.
### other parts
This module will only parse the message body. However, it is possible to include other fields such as hash, committer or date.
```

@@ -43,0 +42,0 @@ My commit message

@@ -83,3 +83,3 @@ 'use strict';

expect(chunk.toString()).to.include('"scope":"category","type":"fix:subcategory","subject":"My subject"');
expect(chunk.toString()).to.include('"references":[{"action":"Close","owner":null,"repository":null,"issue":"10036","raw":"#10036"},{"action":"fix","owner":null,"repository":null,"issue":"9338","raw":"#9338"}]');
expect(chunk.toString()).to.include('"references":[{"action":"Close","owner":null,"repository":null,"issue":"10036","raw":"#10036","prefix":"#"},{"action":"fix","owner":null,"repository":null,"issue":"9338","raw":"#9338","prefix":"#"}]');
expect(chunk.toString()).to.include('"notes":[{"title":"BREAKING NEWS","text":"A lot of changes!"}]');

@@ -86,0 +86,0 @@

@@ -171,3 +171,4 @@ 'use strict';

issue: '123',
raw: '#123'
raw: '#123',
prefix: '#'
}, {

@@ -178,3 +179,4 @@ action: 'fix',

issue: '33',
raw: '#33'
raw: '#33',
prefix: '#'
}]);

@@ -231,3 +233,4 @@ } else if (i === 1) {

issue: '123',
raw: '#123'
raw: '#123',
prefix: '#'
}, {

@@ -238,3 +241,4 @@ action: 'fix',

issue: '33',
raw: '#33'
raw: '#33',
prefix: '#'
}]);

@@ -241,0 +245,0 @@ } else if (i === 1) {

'use strict';
var expect = require('chai').expect;
var parser = require('../lib/parser');
var regex = require('../lib/regex');
describe('parser', function() {
var options;
var regex;
var reg;
var msg;

@@ -14,13 +15,22 @@ var simpleMsg;

beforeEach(function() {
regex = {
notes: /(BREAKING AMEND)[:\s]*(.*)/,
referenceParts: /(?:.*?)??\s*(\S*?)??(?:gh-|#)(\d+)/gi,
references: /(kill|kills|killed|handle|handles|handled)(?:\s+(.*?))(?=(?:kill|kills|killed|handle|handles|handled)|$)/gi
};
options = {
revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (.*)\.$/,
revertCorrespondence: ['header', 'hash'],
fieldPattern: /^-(.*?)-$/,
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject']
headerCorrespondence: ['type', 'scope', 'subject'],
noteKeywords: ['BREAKING AMEND'],
issuePrefixes: ['#', 'gh-'],
referenceActions: [
'kill',
'kills',
'killed',
'handle',
'handles',
'handled'
]
};
reg = regex(options);
msg = parser(

@@ -36,3 +46,3 @@ 'feat(scope): broadcast $destroy event on scope destruction\n' +

options,
regex
reg
);

@@ -51,3 +61,3 @@

options,
regex
reg
);

@@ -58,6 +68,6 @@

options,
regex
reg
);
headerOnlyMsg = parser('header', options, regex);
headerOnlyMsg = parser('header', options, reg);
});

@@ -92,3 +102,3 @@

it('should trim extra newlines', function() {
expect(msg).to.eql(parser(
expect(parser(
'\n\n\n\n\n\n\nfeat(scope): broadcast $destroy event on scope destruction\n\n\n' +

@@ -98,9 +108,38 @@ '\n\n\nperf testing shows that in chrome this change adds 5-15% overhead\n' +

'\n\n\n\nBREAKING AMEND: some breaking change\n' +
'\n\nKills #1, #123\n' +
'\n\n\nkilled #25\n\n\n\n\n' +
'\nhandle #33, Closes #100, Handled #3 kills repo#77\n' +
'kills stevemao/conventional-commits-parser#1',
'\n\n\n\nBREAKING AMEND: An awesome breaking change\n\n\n```\ncode here\n```' +
'\n\nKills #1\n' +
'\n\n\nkilled #25\n\n\n\n\n',
options,
regex
));
reg
)).to.eql({
header: 'feat(scope): broadcast $destroy event on scope destruction',
body: 'perf testing shows that in chrome this change adds 5-15% overhead\n\n\n\nwhen destroying 10k nested scopes where each scope has a $destroy listener',
footer: 'BREAKING AMEND: some breaking change\n\n\n\n\nBREAKING AMEND: An awesome breaking change\n\n\n```\ncode here\n```\n\nKills #1\n\n\n\nkilled #25',
notes: [{
title: 'BREAKING AMEND',
text: 'some breaking change'
}, {
title: 'BREAKING AMEND',
text: 'An awesome breaking change\n\n\n```\ncode here\n```'
}],
references: [{
action: 'Kills',
owner: null,
repository: null,
issue: '1',
raw: '#1',
prefix: '#'
}, {
action: 'killed',
owner: null,
repository: null,
issue: '25',
raw: '#25',
prefix: '#'
}],
revert: null,
scope: 'scope',
subject: 'broadcast $destroy event on scope destruction',
type: 'feat'
});
});

@@ -113,3 +152,3 @@

headerCorrespondence: ['type', 'scope', 'subject']
}, regex);
}, reg);
expect(msg.scope).to.equal('ng:list');

@@ -138,3 +177,3 @@ });

headerCorrespondence: ['scope', 'subject', 'type']
}, regex);
}, reg);

@@ -150,3 +189,3 @@ expect(msg.type).to.equal('fix this');

headerCorrespondence: ['scop', 'subject']
}, regex);
}, reg);

@@ -157,3 +196,3 @@ expect(msg.scope).to.equal(undefined);

it('should reference an issue with an owner', function() {
var msg = parser('handled angular/angular.js#1', options, regex);
var msg = parser('handled angular/angular.js#1', options, reg);
expect(msg.references).to.eql([{

@@ -164,3 +203,4 @@ action: 'handled',

issue: '1',
raw: 'angular/angular.js#1'
raw: 'angular/angular.js#1',
prefix: '#'
}]);

@@ -170,3 +210,3 @@ });

it('should reference an issue with a repository', function() {
var msg = parser('handled angular.js#1', options, regex);
var msg = parser('handled angular.js#1', options, reg);
expect(msg.references).to.eql([{

@@ -177,3 +217,4 @@ action: 'handled',

issue: '1',
raw: 'angular.js#1'
raw: 'angular.js#1',
prefix: '#'
}]);

@@ -183,3 +224,3 @@ });

it('should reference an issue without both', function() {
var msg = parser('handled #1', options, regex);
var msg = parser('handled gh-1', options, reg);
expect(msg.references).to.eql([{

@@ -190,3 +231,4 @@ action: 'handled',

issue: '1',
raw: '#1'
raw: 'gh-1',
prefix: 'gh-'
}]);

@@ -251,3 +293,4 @@ });

issue: '1',
raw: '#1'
raw: '#1',
prefix: '#'
}, {

@@ -258,3 +301,4 @@ action: 'Kills',

issue: '123',
raw: ', #123'
raw: ', #123',
prefix: '#'
}, {

@@ -265,3 +309,4 @@ action: 'killed',

issue: '25',
raw: '#25'
raw: '#25',
prefix: '#'
}, {

@@ -272,3 +317,4 @@ action: 'handle',

issue: '33',
raw: '#33'
raw: '#33',
prefix: '#'
}, {

@@ -279,3 +325,4 @@ action: 'handle',

issue: '100',
raw: ', Closes #100'
raw: ', Closes #100',
prefix: '#'
}, {

@@ -286,3 +333,4 @@ action: 'Handled',

issue: '3',
raw: '#3'
raw: '#3',
prefix: '#'
}, {

@@ -293,3 +341,4 @@ action: 'kills',

issue: '77',
raw: 'repo#77'
raw: 'repo#77',
prefix: '#'
}, {

@@ -300,3 +349,4 @@ action: 'kills',

issue: '1',
raw: 'stevemao/conventional-commits-parser#1'
raw: 'stevemao/conventional-commits-parser#1',
prefix: '#'
}]);

@@ -316,3 +366,3 @@ });

options,
regex
reg
);

@@ -331,3 +381,3 @@

options,
regex
reg
);

@@ -343,3 +393,4 @@ expect(msg.notes[0]).to.eql({

issue: '1',
raw: '#1'
raw: '#1',
prefix: '#'
}, {

@@ -350,3 +401,4 @@ action: 'Kills',

issue: '123',
raw: ', #123'
raw: ', #123',
prefix: '#'
}]);

@@ -364,3 +416,3 @@ expect(msg.footer).to.equal('Kills #1, #123\nBREAKING AMEND: some breaking change');

options,
regex
reg
);

@@ -376,3 +428,4 @@ expect(msg.notes[0]).to.eql({

issue: '1',
raw: '#1'
raw: '#1',
prefix: '#'
}, {

@@ -383,3 +436,4 @@ action: 'Kills',

issue: '123',
raw: ', #123'
raw: ', #123',
prefix: '#'
}]);

@@ -394,7 +448,7 @@ expect(msg.footer).to.equal('Kills #1, #123\nBREAKING AMEND: some breaking change\nsome other breaking change');

'when destroying 10k nested scopes where each scope has a $destroy listener\n' +
'Kills #1, #123\n' +
'Kills gh-1, #123\n' +
'other\n' +
'BREAKING AMEND: some breaking change\n',
options,
regex
reg
);

@@ -410,3 +464,4 @@ expect(msg.notes[0]).to.eql({

issue: '1',
raw: '#1',
raw: 'gh-1',
prefix: 'gh-'
}, {

@@ -417,5 +472,6 @@ action: 'Kills',

issue: '123',
raw: ', #123'
raw: ', #123',
prefix: '#'
}]);
expect(msg.footer).to.equal('Kills #1, #123\nother\nBREAKING AMEND: some breaking change');
expect(msg.footer).to.equal('Kills gh-1, #123\nother\nBREAKING AMEND: some breaking change');
});

@@ -426,14 +482,2 @@ });

it('should parse hash', function() {
regex = {
notes: /(BREAKING AMEND)[:\s]*(.*)/,
referenceParts: /(?:.*?)??\s*(\S*?)??(?:gh-|#)(\d+)/gi,
references: /(kill|kills|killed|handle|handles|handled)(?:\s+(.*?))(?=(?:kill|kills|killed|handle|handles|handled)|$)/gi
};
options = {
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
fieldPattern: /^-(.*?)-$/
};
msg = parser(

@@ -444,3 +488,3 @@ 'My commit message\n' +

options,
regex
reg
);

@@ -452,14 +496,2 @@

it('should parse sideNotes', function() {
regex = {
notes: /(BREAKING AMEND)[:\s]*(.*)/,
referenceParts: /(?:.*?)??\s*(\S*?)??(?:gh-|#)(\d+)/gi,
references: /(kill|kills|killed|handle|handles|handled)(?:\s+(.*?))(?=(?:kill|kills|killed|handle|handles|handled)|$)/gi
};
options = {
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
fieldPattern: /^-(.*?)-$/
};
msg = parser(

@@ -472,3 +504,3 @@ 'My commit message\n' +

options,
regex
reg
);

@@ -482,14 +514,2 @@

it('should parse committer name and email', function() {
regex = {
notes: /(BREAKING AMEND)[:\s]*(.*)/,
referenceParts: /(?:.*?)??\s*(\S*?)??(?:gh-|#)(\d+)/gi,
references: /(kill|kills|killed|handle|handles|handled)(?:\s+(.*?))(?=(?:kill|kills|killed|handle|handles|handled)|$)/gi
};
options = {
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerCorrespondence: ['type', 'scope', 'subject'],
fieldPattern: /^-(.*?)-$/
};
msg = parser(

@@ -502,3 +522,3 @@ 'My commit message\n' +

options,
regex
reg
);

@@ -513,13 +533,2 @@

it('should parse revert', function() {
options = {
revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (.*)\.$/,
revertCorrespondence: ['header', 'hash']
};
regex = {
notes: /(BREAKING AMEND)[:\s]*(.*)/,
referenceParts: /(?:.*?)??\s*(\S*?)??(?:gh-|#)(\d+)/gi,
references: /(close)(?:\s+(.*?))(?=(?:close)|$)/gi
};
msg = parser(

@@ -529,3 +538,3 @@ 'Revert "throw an error if a callback is passed to animate methods"\n\n' +

options,
regex
reg
);

@@ -540,13 +549,2 @@

it('should parse revert even if a field is missing', function() {
options = {
revertPattern: /^Revert\s"([\s\S]*)"\s*This reverts commit (.*)\.$/,
revertCorrespondence: ['header', 'hash']
};
regex = {
notes: /(BREAKING AMEND)[:\s]*(.*)/,
referenceParts: /(?:.*?)??\s*(\S*?)??(?:gh-|#)(\d+)/gi,
references: /(close)(?:\s+(.*?))(?=(?:close)|$)/gi
};
msg = parser(

@@ -556,3 +554,3 @@ 'Revert ""\n\n' +

options,
regex
reg
);

@@ -559,0 +557,0 @@

@@ -111,3 +111,4 @@ 'use strict';

expect(match[1]).to.equal(undefined);
expect(match[2]).to.equal('1');
expect(match[2]).to.equal('#');
expect(match[3]).to.equal('1');
});

@@ -119,3 +120,3 @@

expect(match[1]).to.equal(undefined);
expect(match[2]).to.equal('1');
expect(match[3]).to.equal('1');
});

@@ -127,3 +128,3 @@

expect(match[1]).to.equal('repo');
expect(match[2]).to.equal('1');
expect(match[3]).to.equal('1');
});

@@ -136,3 +137,3 @@

expect(match[1]).to.equal(undefined);
expect(match[2]).to.equal('1');
expect(match[3]).to.equal('1');

@@ -142,3 +143,3 @@ match = reReferenceParts.exec(string);

expect(match[1]).to.equal(undefined);
expect(match[2]).to.equal('2');
expect(match[3]).to.equal('2');

@@ -148,3 +149,3 @@ match = reReferenceParts.exec(string);

expect(match[1]).to.equal(undefined);
expect(match[2]).to.equal('3');
expect(match[3]).to.equal('3');

@@ -154,3 +155,3 @@ match = reReferenceParts.exec(string);

expect(match[1]).to.equal('repo');
expect(match[2]).to.equal('4');
expect(match[3]).to.equal('4');
});

@@ -167,3 +168,4 @@

expect(match[1]).to.equal(undefined);
expect(match[2]).to.equal('1');
expect(match[2]).to.equal('gh-');
expect(match[3]).to.equal('1');

@@ -173,3 +175,4 @@ match = reReferenceParts.exec(string);

expect(match[1]).to.equal(undefined);
expect(match[2]).to.equal('3');
expect(match[2]).to.equal('prefix-');
expect(match[3]).to.equal('3');
});

@@ -176,0 +179,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc