conventional-commits-parser
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -6,3 +6,19 @@ # Change Log | ||
<a name="2.0.1"></a> | ||
<a name="2.1.0"></a> | ||
# [2.1.0](https://github.com/conventional-changelog/conventional-commits-parser/compare/conventional-commits-parser@2.0.1...conventional-commits-parser@2.1.0) (2017-12-08) | ||
### Bug Fixes | ||
* always parse references ([e84a9ae](https://github.com/conventional-changelog/conventional-commits-parser/commit/e84a9ae)), closes [#248](https://github.com/conventional-changelog/conventional-commits-parser/issues/248) | ||
### Features | ||
* make comment stripping optional ([db5b711](https://github.com/conventional-changelog/conventional-commits-parser/commit/db5b711)), closes [#251](https://github.com/conventional-changelog/conventional-commits-parser/issues/251) | ||
<a name="2.0.1"></a> | ||
## [2.0.1](https://github.com/conventional-changelog/conventional-commits-parser/compare/conventional-commits-parser@2.0.0...conventional-commits-parser@2.0.1) (2017-11-13) | ||
@@ -18,3 +34,3 @@ | ||
<a name="2.0.0"></a> | ||
<a name="2.0.0"></a> | ||
# 2.0.0 (2017-07-17) | ||
@@ -21,0 +37,0 @@ |
@@ -5,2 +5,4 @@ 'use strict'; | ||
var CATCH_ALL = /()(.+)/gi; | ||
function append(src, line) { | ||
@@ -16,2 +18,51 @@ if (src) { | ||
function getCommentFilter(char) { | ||
return function(line) { | ||
return line.charAt(0) !== char; | ||
}; | ||
} | ||
function getReferences(input, regex) { | ||
var references = []; | ||
var referenceSentences; | ||
var referenceMatch; | ||
var reApplicable = input.match(regex.references) !== null ? | ||
regex.references : | ||
CATCH_ALL; | ||
while (referenceSentences = reApplicable.exec(input)) { | ||
var action = referenceSentences[1] || null; | ||
var sentence = referenceSentences[2]; | ||
while (referenceMatch = regex.referenceParts.exec(sentence)) { | ||
var owner = null; | ||
var repository = referenceMatch[1] || ''; | ||
var ownerRepo = repository.split('/'); | ||
if (ownerRepo.length > 1) { | ||
owner = ownerRepo.shift(); | ||
repository = ownerRepo.join('/'); | ||
} | ||
var reference = { | ||
action: action, | ||
owner: owner, | ||
repository: repository || null, | ||
issue: referenceMatch[3], | ||
raw: referenceMatch[0], | ||
prefix: referenceMatch[2] | ||
}; | ||
references.push(reference); | ||
} | ||
} | ||
return references; | ||
} | ||
function passTrough() { | ||
return true; | ||
} | ||
function parser(raw, options, regex) { | ||
@@ -32,4 +83,2 @@ if (!raw || !raw.trim()) { | ||
var mergeMatch; | ||
var referenceSentences; | ||
var referenceMatch; | ||
var currentProcessedField; | ||
@@ -39,5 +88,8 @@ var mentionsMatch; | ||
var otherFields = {}; | ||
var lines = trimOffNewlines(raw).split(/\r?\n/).filter(function(line) { | ||
return line[0] !== '#'; | ||
}); | ||
var commentFilter = typeof options.commentChar === 'string' ? | ||
getCommentFilter(options.commentChar) : | ||
passTrough; | ||
var lines = trimOffNewlines(raw).split(/\r?\n/).filter(commentFilter); | ||
var continueNote = false; | ||
@@ -55,6 +107,2 @@ var isBody = true; | ||
var reNotes = regex.notes; | ||
var reReferenceParts = regex.referenceParts; | ||
var reReferences = regex.references; | ||
var body = null; | ||
@@ -126,32 +174,7 @@ var footer = null; | ||
// incase people reference an issue in the header | ||
while (referenceSentences = reReferences.exec(header)) { | ||
var action = referenceSentences[1] || null; | ||
var sentence = referenceSentences[2]; | ||
while (referenceMatch = reReferenceParts.exec(sentence)) { | ||
var owner = null; | ||
var repository = referenceMatch[1]; | ||
Array.prototype.push.apply(references, getReferences(header, { | ||
references: regex.references, | ||
referenceParts: regex.referenceParts | ||
})); | ||
if (repository) { | ||
var ownerRepo = repository.split('/'); | ||
if (ownerRepo.length > 1) { | ||
owner = ownerRepo.shift(); | ||
repository = ownerRepo.join('/'); | ||
} | ||
} else { | ||
repository = null; | ||
} | ||
var reference = { | ||
action: action, | ||
owner: owner, | ||
repository: repository, | ||
issue: referenceMatch[3], | ||
raw: referenceMatch[0], | ||
prefix: referenceMatch[2] | ||
}; | ||
references.push(reference); | ||
} | ||
} | ||
// body or footer | ||
@@ -178,3 +201,3 @@ _.forEach(lines, function(line) { | ||
// this is a new important note | ||
var notesMatch = line.match(reNotes); | ||
var notesMatch = line.match(regex.notes); | ||
if (notesMatch) { | ||
@@ -195,36 +218,15 @@ continueNote = true; | ||
// this references an issue | ||
while (referenceSentences = reReferences.exec(line)) { | ||
var action = referenceSentences[1] || null; | ||
var sentence = referenceSentences[2]; | ||
while (referenceMatch = reReferenceParts.exec(sentence)) { | ||
referenceMatched = true; | ||
continueNote = false; | ||
isBody = false; | ||
var lineReferences = getReferences(line, { | ||
references: regex.references, | ||
referenceParts: regex.referenceParts | ||
}); | ||
var owner = null; | ||
var repository = referenceMatch[1]; | ||
if (lineReferences.length > 0) { | ||
isBody = false; | ||
referenceMatched = true; | ||
continueNote = false; | ||
} | ||
if (repository) { | ||
var ownerRepo = repository.split('/'); | ||
if (ownerRepo.length > 1) { | ||
owner = ownerRepo.shift(); | ||
repository = ownerRepo.join('/'); | ||
} | ||
} else { | ||
repository = null; | ||
} | ||
Array.prototype.push.apply(references, lineReferences); | ||
var reference = { | ||
action: action, | ||
owner: owner, | ||
repository: repository, | ||
issue: referenceMatch[3], | ||
raw: referenceMatch[0], | ||
prefix: referenceMatch[2] | ||
}; | ||
references.push(reference); | ||
} | ||
} | ||
if (referenceMatched) { | ||
@@ -236,3 +238,2 @@ footer = append(footer, line); | ||
// this is the continued important note | ||
if (continueNote) { | ||
@@ -245,9 +246,5 @@ notes[notes.length - 1].text = append(notes[notes.length - 1].text, line); | ||
// this is the body | ||
if (isBody) { | ||
body = append(body, line); | ||
} | ||
// this is the continued footer | ||
else { | ||
} else { | ||
footer = append(footer, line); | ||
@@ -254,0 +251,0 @@ } |
{ | ||
"name": "conventional-commits-parser", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Parse raw conventional commits", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/conventional-changelog/conventional-commits-parser", |
@@ -228,3 +228,3 @@ # [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-image]][daviddm-url] [![Coverage Status][coveralls-image]][coveralls-url] | ||
If configured correctly, the parsed result would be | ||
If configured correctly, the parsed result would be | ||
@@ -244,2 +244,11 @@ ```js | ||
##### commentChar | ||
Type: `string` or `null` Default: null | ||
What commentChar to use. By default it is `null`, so no comments are stripped. | ||
Set to `#` if you pass the contents of `.git/COMMIT_EDITMSG` directly. | ||
If you have configured the git commentchar via `git config core.commentchar` you'll want to pass what you have set there. | ||
##### warn | ||
@@ -246,0 +255,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45328
371
479
1