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

Commit

Permalink
fix(headerPattern): change how capturing groups works
Browse files Browse the repository at this point in the history
The first capturing group captures **type**, second captures **scope** and third captures **subject**
  • Loading branch information
stevemao committed Mar 1, 2015
1 parent 8868406 commit 1a73a48
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ The maximum subject length.

##### headerPattern

Type: `regex` Default: `/^(\w*)(\(([\w\$\.\-\* ]*)\))?\: (.*)$/`
Type: `regex` Default: `/^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/`

Used to match header pattern.
Used to match header pattern. The first capturing group captures **type**, second captures **scope** and third captures **subject**

##### closeKeywords

Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ var through = require('through2');
function conventionalCommitsParser(options) {
options = extend({
maxSubjectLength: 80,
headerPattern: /^(\w*)(\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
closeKeywords: [
'close',
'closes',
Expand Down
10 changes: 5 additions & 5 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ function parser(raw, options) {
}

match = msg.header.match(options.headerPattern);
if (!match || !match[1] || !match[4]) {
if (!match || !match[1] || !match[3]) {
return null;
}

if (match[4].length > options.maxSubjectLength) {
match[4] = match[4].substr(0, options.maxSubjectLength);
if (match[3].length > options.maxSubjectLength) {
match[3] = match[3].substr(0, options.maxSubjectLength);
}

msg.type = match[1];
msg.scope = match[3];
msg.subject = match[4];
msg.scope = match[2];
msg.subject = match[3];

_.forEach(lines, function(line) {
var issue;
Expand Down
4 changes: 2 additions & 2 deletions test/parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var parser = require('../lib/parser');
describe('parseRawCommit', function() {
var options = {
maxSubjectLength: 80,
headerPattern: /^(\w*)(\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
closeKeywords: [
'kill',
'kills',
Expand All @@ -21,7 +21,7 @@ describe('parseRawCommit', function() {

var shortSubjectOptions = {
maxSubjectLength: 10,
headerPattern: /^(\w*)(\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
headerPattern: /^(\w*)(?:\(([\w\$\.\-\* ]*)\))?\: (.*)$/,
closeKeywords: [
'close',
],
Expand Down

0 comments on commit 1a73a48

Please sign in to comment.