diff options
| author | Igor Minar | 2013-01-22 22:49:00 -0800 |
|---|---|---|
| committer | Igor Minar | 2013-01-22 22:49:00 -0800 |
| commit | 07a58dd7669431d33b61f8c3213c31eff744d02a (patch) | |
| tree | dfba035aba1829807b49992dc2545a4c9525e2ca | |
| parent | ffe5e01584ec1c10930a9a01ce4cec2ec888966b (diff) | |
| download | angular.js-07a58dd7669431d33b61f8c3213c31eff744d02a.tar.bz2 | |
chore(changelog.js): improve the changelog script
| -rwxr-xr-x | changelog.js | 49 | ||||
| -rw-r--r-- | changelog.spec.js | 6 |
2 files changed, 30 insertions, 25 deletions
diff --git a/changelog.js b/changelog.js index 746b0f9d..c331c7cf 100755 --- a/changelog.js +++ b/changelog.js @@ -36,16 +36,15 @@ var parseRawCommit = function(raw) { msg.breaks = []; lines.forEach(function(line) { - match = line.match(/Closes\s#(\d+)/); + match = line.match(/(?:Closes|Fixes)\s#(\d+)/); if (match) msg.closes.push(parseInt(match[1])); }); - + match = raw.match(/BREAKING CHANGE:([\s\S]*)/); if (match) { - console.log('found!!!') - msg.breaks.push(match[1]); + msg.breaking = match[1]; } - + msg.body = lines.join('\n'); match = msg.subject.match(/^(.*)\((.*)\)\:\s(.*)$/); @@ -88,7 +87,8 @@ var currentDate = function() { }; -var printSection = function(stream, title, section) { +var printSection = function(stream, title, section, printCommitLinks) { + printCommitLinks = printCommitLinks === undefined ? true : printCommitLinks; var components = Object.getOwnPropertyNames(section).sort(); if (!components.length) return; @@ -109,11 +109,15 @@ var printSection = function(stream, title, section) { } section[name].forEach(function(commit) { - stream.write(util.format('%s %s (%s', prefix, commit.subject, linkToCommit(commit.hash))); - if (commit.closes.length) { - stream.write(', closes ' + commit.closes.map(linkToIssue).join(', ')); + if (printCommitLinks) { + stream.write(util.format('%s %s\n (%s', prefix, commit.subject, linkToCommit(commit.hash))); + if (commit.closes.length) { + stream.write(',\n ' + commit.closes.map(linkToIssue).join(', ')); + } + stream.write(')\n'); + } else { + stream.write(util.format('%s %s', prefix, commit.subject)); } - stream.write(')\n'); }); }); @@ -122,7 +126,7 @@ var printSection = function(stream, title, section) { var readGitLog = function(grep, from) { - var deffered = q.defer(); + var deferred = q.defer(); // TODO(vojta): if it's slow, use spawn and stream it instead child.exec(util.format(GIT_LOG_CMD, grep, '%H%n%s%n%b%n==END==', from), function(code, stdout, stderr) { @@ -133,10 +137,10 @@ var readGitLog = function(grep, from) { if (commit) commits.push(commit); }); - deffered.resolve(commits); + deferred.resolve(commits); }); - return deffered.promise; + return deferred.promise; }; @@ -158,29 +162,30 @@ var writeChangelog = function(stream, commits, version) { section[component].push(commit); } - commit.breaks.forEach(function(breakMsg) { - sections.breaks[EMPTY_COMPONENT].push({ - subject: breakMsg, + if (commit.breaking) { + sections.breaks[component] = sections.breaks[component] || []; + sections.breaks[component].push({ + subject: util.format("due to %s,\n %s", linkToCommit(commit.hash), commit.breaking), hash: commit.hash, closes: [] }); - }); + }; }); stream.write(util.format(HEADER_TPL, version, version, currentDate())); printSection(stream, 'Bug Fixes', sections.fix); printSection(stream, 'Features', sections.feat); - printSection(stream, 'Breaking Changes', sections.breaks); + printSection(stream, 'Breaking Changes', sections.breaks, false); } var getPreviousTag = function() { - var deffered = q.defer(); + var deferred = q.defer(); child.exec(GIT_TAG_CMD, function(code, stdout, stderr) { - if (code) deffered.reject('Cannot get the previous tag.'); - else deffered.resolve(stdout.replace('\n', '')); + if (code) deferred.reject('Cannot get the previous tag.'); + else deferred.resolve(stdout.replace('\n', '')); }); - return deffered.promise; + return deferred.promise; }; diff --git a/changelog.spec.js b/changelog.spec.js index 1d3b7fe8..595ed84d 100644 --- a/changelog.spec.js +++ b/changelog.spec.js @@ -34,10 +34,10 @@ describe('changelog.js', function() { '13f31602f396bc269076ab4d389cfd8ca94b20ba\n' + 'feat(ng-list): Allow custom separator\n' + 'bla bla bla\n\n' + - 'Breaks first breaking change\nsomething else\n' + - 'Breaks another breaking change\n'); + 'BREAKING CHANGE: first breaking change\nsomething else\n' + + 'another line with more info\n'); - expect(msg.breaks).toEqual(['first breaking change', 'another breaking change']); + expect(msg.breaking).toEqual(' first breaking change\nsomething else\nanother line with more info\n'); }); }); }); |
