chore(publishing): put malformed commit messages to "other"; do not output empty sections

Closes #1557
This commit is contained in:
Yegor Jbanov 2015-04-27 11:48:53 -07:00 committed by Misko Hevery
parent 3bb3bff1f2
commit 414e58edb5
1 changed files with 27 additions and 14 deletions

View File

@ -52,13 +52,14 @@ var parseRawCommit = function(raw) {
if (!match || !match[1] || !match[3]) { if (!match || !match[1] || !match[3]) {
warn('Incorrect message: %s %s', msg.hash, msg.subject); warn('Incorrect message: %s %s', msg.hash, msg.subject);
return null; msg.type = 'other';
msg.component = 'other';
} else {
msg.type = match[1];
msg.component = match[2];
msg.subject = match[3];
} }
msg.type = match[1];
msg.component = match[2];
msg.subject = match[3];
return msg; return msg;
}; };
@ -86,10 +87,13 @@ var currentDate = function() {
var printSection = function(stream, title, section, printCommitLinks) { var printSection = function(stream, title, section, printCommitLinks) {
printCommitLinks = printCommitLinks === undefined ? true : printCommitLinks; printCommitLinks = printCommitLinks === undefined ? true : printCommitLinks;
var components = Object.getOwnPropertyNames(section).sort(); var components = Object.getOwnPropertyNames(section).sort();
var buffer = '';
var sectionIsEmpty = true;
if (!components.length) return; var write = function(str) {
buffer += str;
stream.write(util.format('\n## %s\n\n', title)); sectionIsEmpty = false;
}
components.forEach(function(name) { components.forEach(function(name) {
var prefix = '-'; var prefix = '-';
@ -97,7 +101,7 @@ var printSection = function(stream, title, section, printCommitLinks) {
if (name !== EMPTY_COMPONENT) { if (name !== EMPTY_COMPONENT) {
if (nested) { if (nested) {
stream.write(util.format('- **%s:**\n', name)); write(util.format('- **%s:**\n', name));
prefix = ' -'; prefix = ' -';
} else { } else {
prefix = util.format('- **%s:**', name); prefix = util.format('- **%s:**', name);
@ -106,17 +110,24 @@ var printSection = function(stream, title, section, printCommitLinks) {
section[name].forEach(function(commit) { section[name].forEach(function(commit) {
if (printCommitLinks) { if (printCommitLinks) {
stream.write(util.format('%s %s\n (%s', prefix, commit.subject, linkToCommit(commit.hash))); write(util.format('%s %s\n (%s', prefix, commit.subject, linkToCommit(commit.hash)));
if (commit.closes.length) { if (commit.closes.length) {
stream.write(',\n ' + commit.closes.map(linkToIssue).join(', ')); write(',\n ' + commit.closes.map(linkToIssue).join(', '));
} }
stream.write(')\n'); write(')\n');
} else { } else {
stream.write(util.format('%s %s\n', prefix, commit.subject)); write(util.format('%s %s\n', prefix, commit.subject));
} }
}); });
}); });
if (sectionIsEmpty) {
// Nothing in this section. Skip.
return;
}
stream.write(util.format('\n## %s\n\n', title));
stream.write(buffer);
stream.write('\n'); stream.write('\n');
}; };
@ -145,7 +156,8 @@ var writeChangelog = function(stream, commits, version) {
fix: {}, fix: {},
feat: {}, feat: {},
perf: {}, perf: {},
breaks: {} breaks: {},
other: {}
}; };
sections.breaks[EMPTY_COMPONENT] = []; sections.breaks[EMPTY_COMPONENT] = [];
@ -173,6 +185,7 @@ var writeChangelog = function(stream, commits, version) {
printSection(stream, 'Features', sections.feat); printSection(stream, 'Features', sections.feat);
printSection(stream, 'Performance Improvements', sections.perf); printSection(stream, 'Performance Improvements', sections.perf);
printSection(stream, 'Breaking Changes', sections.breaks, false); printSection(stream, 'Breaking Changes', sections.breaks, false);
printSection(stream, 'Other (malformed commit messages)', sections.other);
}; };