conventional-changelog
Advanced tools
Comparing version 0.0.9 to 0.0.10
@@ -52,3 +52,3 @@ var extend = require('lodash.assign'); | ||
options.format, | ||
options.from ? options.from+'..'+options.to : '' | ||
options.from ? '"' + options.from + '..' + options.to + '"' : '' | ||
); | ||
@@ -66,3 +66,3 @@ | ||
var COMMIT_PATTERN = /^(\w*)(\(([\w\$\.\-\*]*)\))?\: (.*)$/; | ||
var COMMIT_PATTERN = /^(\w*)(\(([\w\$\.\-\* ]*)\))?\: (.*)$/; | ||
var MAX_SUBJECT_LENGTH = 80; | ||
@@ -82,3 +82,3 @@ function parseRawCommit(raw, options) { | ||
msg.subject = msg.subject.replace(/\s*(?:Closes|Fixes|Resolves)\s#(\d+)/, function(_, i) { | ||
msg.subject = msg.subject.replace(/\s*(?:Closes|Fixes|Resolves)\s#(\d+)/ig, function(_, i) { | ||
msg.closes.push(parseInt(i, 10)); | ||
@@ -89,9 +89,10 @@ return ''; | ||
lines.forEach(function(line) { | ||
match = line.match(/(?:Closes|Fixes|Resolves)\s((?:#\d+(?:\,\s)?)+)/); | ||
match = line.match(/(?:Closes|Fixes|Resolves)\s((?:#\d+(?:\,\s)?)+)/ig); | ||
if (match) { | ||
match[1].replace(/[\s#]/g, '').split(',').forEach(function(i) { | ||
msg.closes.push(parseInt(i, 10)); | ||
match && match.forEach(function(m) { | ||
m && m.split(',').forEach(function(i) { | ||
var issue = i.match(/\d+/); | ||
issue && msg.closes.push(parseInt(issue[0], 10)); | ||
}); | ||
} | ||
}); | ||
}); | ||
@@ -98,0 +99,0 @@ |
@@ -5,2 +5,6 @@ var es = require('event-stream'); | ||
var LINK_VERSION = '[## %s%s](%s/releases/tag/%s)'; | ||
var VERSION = '## %s %s'; | ||
var LINK_PATCH_VERSION = '[### %s%s](%s/releases/tag/%s)'; | ||
var PATCH_VERSION = '### %s %s'; | ||
var LINK_ISSUE = '[#%s](%s/issues/%s)'; | ||
@@ -16,2 +20,14 @@ var ISSUE = '(#%s)'; | ||
function getVersionLink (repository, version, subtitle) { | ||
subtitle = subtitle ? ' ' + subtitle : ''; | ||
return repository ? | ||
util.format(LINK_VERSION, version, subtitle, repository, version) : | ||
util.format(VERSION, version, version, subtitle); | ||
} | ||
function getPatchVersionLink (repository, version, subtitle) { | ||
subtitle = subtitle ? ' ' + subtitle : ''; | ||
return repository ? | ||
util.format(LINK_PATCH_VERSION, version, subtitle, repository, version) : | ||
util.format(PATCH_VERSION, version, version, subtitle); | ||
} | ||
function getIssueLink(repository, issue) { | ||
@@ -31,2 +47,4 @@ return repository ? | ||
options = extend({ | ||
versionLink: getVersionLink.bind(null, options.repository), | ||
patchVersionLink: getPatchVersionLink.bind(null, options.repository), | ||
issueLink: getIssueLink.bind(null, options.repository), | ||
@@ -77,11 +95,25 @@ commitLink: getCommitLink.bind(null, options.repository) | ||
var PATCH_HEADER_TPL = '<a name="%s"></a>\n### %s %s (%s)\n\n'; | ||
var MINOR_HEADER_TPL = '<a name="%s"></a>\n## %s %s (%s)\n\n'; | ||
var LINK_HEADER_TPL = '%s (%s)\n\n'; | ||
var PLAIN_HEADER_TPL = '<a name="%s"></a>\n%s (%s)\n\n'; | ||
var EMPTY_COMPONENT = '$$'; | ||
function Writer(stream, options) { | ||
options = extend({ | ||
versionLink: getVersionLink.bind(null, options.repository), | ||
patchVersionLink: getPatchVersionLink.bind(null, options.repository), | ||
issueLink: getIssueLink.bind(null, options.repository), | ||
commitLink: getCommitLink.bind(null, options.repository) | ||
}, options || {}); | ||
this.header = function(version) { | ||
var subtitle = options.subtitle || ''; | ||
var header = version.split('.')[2] === '0' ? MINOR_HEADER_TPL : PATCH_HEADER_TPL; | ||
stream.write(util.format(header, version, version, subtitle, currentDate())); | ||
var versionText = version.split('.')[2] === '0' ? | ||
options.versionLink(version, subtitle) : | ||
options.patchVersionLink(version, subtitle); | ||
if (options.repository) { | ||
stream.write(util.format(LINK_HEADER_TPL, versionText, currentDate())); | ||
} else { | ||
stream.write(util.format(PLAIN_HEADER_TPL, version, versionText, currentDate())); | ||
} | ||
}; | ||
@@ -129,3 +161,3 @@ | ||
}; | ||
}; | ||
} | ||
@@ -132,0 +164,0 @@ function currentDate() { |
{ | ||
"name": "conventional-changelog", | ||
"codename": "change", | ||
"version": "0.0.9", | ||
"version": "0.0.10", | ||
"description": "Generate a markdown changelog from git commit metadata", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha test/*.js index.js lib/*.js" | ||
"test": "mocha test/*.js index.js lib/*.js --no-colors" | ||
}, | ||
@@ -31,3 +31,3 @@ "files": [ | ||
{ | ||
"name": "Andy Joslin" | ||
"name": "Andrew Joslin" | ||
} | ||
@@ -34,0 +34,0 @@ ], |
@@ -8,14 +8,20 @@ conventional-changelog | ||
Generate a changelog from git metadata, using [these commit conventions](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/). | ||
Generate a changelog from git metadata, using the AngularJS commit conventions. | ||
View [CONVENTIONS.md](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md) for a synposis of the conventions with commit examples. | ||
- [Synopsis of Conventions in CONVENTIONS.md](https://github.com/ajoslin/conventional-changelog/blob/master/CONVENTIONS.md) | ||
- [Full Convention Spec on Google Docs](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/) | ||
Adapted from code originally written by @vojtajina, from grunt-conventional-changelog. | ||
Adapted from code originally written by @vojtajina and @btford in [grunt-conventional-changelog](https://github.com/btford/grunt-conventional-changelog). | ||
## Example output | ||
- https://github.com/ajoslin/conventional-changelog/blob/master/CHANGELOG.md | ||
- https://github.com/karma-runner/karma/blob/master/CHANGELOG.md | ||
Recommended usage: use in your workflow with [https://github.com/btford/grunt-conventional-changelog](grunt-conventional-changelog). | ||
## Roadmap | ||
- Make it return a stream | ||
- Add a proper command line interface | ||
- Add configurable subjects & sections | ||
## Documentation | ||
@@ -42,2 +48,4 @@ | ||
##### The Most Important Options | ||
* `version` `{string}` - The version to be written to the changelog. For example, `{version: require('./package.json').version}` | ||
@@ -49,6 +57,2 @@ | ||
* `commitLink` `{function(commitHash)}` - If repository is provided, this function will be used to link to commits. By default, returns a github commit link based on options.repository: `opts.repository + '/commit/' + hash` | ||
* `issueLink` `{function(issueId)}` - If repository is provided, this function will be used to link to issues. By default, returns a github issue link based on options.repository: `opts.repository + '/issues/' + id` | ||
* `from` `{string}` - Which commit the changelog should start at. By default, uses previous tag, or if no previous tag the first commit. | ||
@@ -58,4 +62,14 @@ | ||
* `file` `{string}` - Which file to read the current changelog from and prepend the new changelog's contents to. By default, uses `'CHANGELOG.md'`. | ||
* `file` `{string}` - Which file to read the current changelog from and prepend the new changelog's contents to. By default, uses `'CHANGELOG.md'` | ||
##### The "I really want to get crazy" Options | ||
* `versionLink` `{function(version, subtitle)}` - If repository is provided, this function will be used to link to major and minor versions. By default, returns a github version link based on options.repository: `opts.repository + '/releases/tag/' + version` | ||
* `patchVersionLink` `{function(version, subtitle)}` - If repository is provided, this function will be used to link to patch versions. By default, returns a github version link based on options.repository: `opts.repository + '/releases/tag/' + version` | ||
* `commitLink` `{function(commitHash)}` - If repository is provided, this function will be used to link to commits. By default, returns a github commit link based on options.repository: `opts.repository + '/commit/' + hash` | ||
* `issueLink` `{function(issueId)}` - If repository is provided, this function will be used to link to issues. By default, returns a github issue link based on options.repository: `opts.repository + '/issues/' + id` | ||
* `log` `{function()}` - What logging function to use. For example, `{log: grunt.log.ok}`. By default, uses `console.log`. | ||
@@ -66,2 +80,3 @@ | ||
## License | ||
BSD |
@@ -41,42 +41,68 @@ describe('git', function() { | ||
}); | ||
it('should parse Closes in the subject (and remove it)', function() { | ||
var msg = git.parseRawCommit( | ||
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'feat(xxx): Whatever Closes #24\n' + | ||
'bla bla bla\n\n' + | ||
'What not ?\n' | ||
); | ||
expect(msg.closes).to.deep.equal([24]); | ||
expect(msg.subject).to.equal('Whatever'); | ||
['Closes', 'Fixes', 'Resolves'].forEach(function(closeWord) { | ||
it('should parse ' + closeWord + ' in the subject (and remove it)', function() { | ||
var msg = git.parseRawCommit( | ||
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'feat(xxx): Whatever ' + closeWord + ' #24\n' + | ||
'bla bla bla\n\n' + | ||
'What not ?\n' | ||
); | ||
expect(msg.closes).to.deep.equal([24]); | ||
expect(msg.subject).to.equal('Whatever'); | ||
}); | ||
it('should work with lowercase ' + closeWord + ' in the subject', function() { | ||
var msg = git.parseRawCommit( | ||
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'feat(xxx): Whatever ' + closeWord.toLowerCase() + ' #24\n' + | ||
'bla bla bla\n\n' + | ||
'What not ?\n' | ||
); | ||
expect(msg.closes).to.deep.equal([24]); | ||
expect(msg.subject).to.equal('Whatever'); | ||
}); | ||
it('should parse multiple comma-separated issues closed with ' + closeWord + ' #1, #2', function() { | ||
var msg = git.parseRawCommit( | ||
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'fix(yyy): Very cool commit\n' + | ||
'bla bla bla\n\n' + | ||
closeWord + ' #1, #22, #33\n' + | ||
'What not ?\n' | ||
); | ||
expect(msg.closes).to.deep.equal([1, 22, 33]); | ||
expect(msg.subject).to.equal('Very cool commit'); | ||
}); | ||
}); | ||
it('should parse Fixes in the subject (and remove it)', function() { | ||
it('should parse multiple period-separated issues closed with all closed words', function() { | ||
var msg = git.parseRawCommit( | ||
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'feat(xxx): Whatever Fixes #25\n' + | ||
'bla bla bla\n\n' + | ||
'fix(zzz): Very cool commit\n' + | ||
'bla bla bla\n\n' + | ||
'Closes #2, #3. Resolves #4. Fixes #5. Fixes #6.\n' + | ||
'What not ?\n' | ||
); | ||
expect(msg.closes).to.deep.equal([25]); | ||
expect(msg.subject).to.equal('Whatever'); | ||
expect(msg.closes).to.deep.equal([2,3,4,5,6]); | ||
expect(msg.subject).to.equal('Very cool commit'); | ||
}); | ||
it('should parse multiple issues closed with Closes #1, #2', function() { | ||
it('should parse a msg without scope', function() { | ||
var msg = git.parseRawCommit( | ||
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'feat(xxx): Very cool commit\n' + | ||
'chore: some chore\n' + | ||
'bla bla bla\n\n' + | ||
'Closes #1, #22, #33\n' + | ||
'What not ?\n' | ||
'BREAKING CHANGE: some breaking change\n' | ||
); | ||
expect(msg.closes).to.deep.equal([1, 22, 33]); | ||
expect(msg.type).to.equal('chore'); | ||
expect(msg.subject).to.equal('some chore'); | ||
}); | ||
it('should parse a msg without scope', function() { | ||
it('should parse a scope with spaces', function() { | ||
var msg = git.parseRawCommit( | ||
'13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + | ||
'chore: some chore bullshit\n' + | ||
'bla bla bla\n\n' + | ||
'chore(scope with spaces): some chore\n' + | ||
'bla bla bla\n\n' + | ||
'BREAKING CHANGE: some breaking change\n' | ||
); | ||
expect(msg.type).to.equal('chore'); | ||
expect(msg.subject).to.equal('some chore'); | ||
expect(msg.component).to.equal('scope with spaces'); | ||
}); | ||
}); | ||
}); |
@@ -21,2 +21,4 @@ describe("Writer", function() { | ||
return new writer.Writer(stream, { | ||
subtitle: 'subby', | ||
repository: 'github.com/user/repo', | ||
issueLink: function(id) { | ||
@@ -35,8 +37,8 @@ return id; | ||
writer.header('0.1.0'); | ||
expect(log.indexOf('<a name="0.1.0"></a>\n## 0.1.0')).to.equal(0); | ||
expect(log).to.contain('[## 0.1.0 subby](github.com/user/repo/releases/tag/0.1.0)'); | ||
}); | ||
it('patch version', function() { | ||
var writer = setup(); | ||
writer.header('0.0.1'); | ||
expect(log.indexOf('<a name="0.0.1"></a>\n### 0.0.1')).to.equal(0); | ||
writer.header('0.0.3'); | ||
expect(log).to.contain('[### 0.0.3 subby](github.com/user/repo/releases/tag/0.0.3)'); | ||
}); | ||
@@ -43,0 +45,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
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
20613
471
78