Skip to content

Commit

Permalink
chore(changelog.js): improve the changelog script
Browse files Browse the repository at this point in the history
  • Loading branch information
IgorMinar committed Jan 23, 2013
1 parent ffe5e01 commit 07a58dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 25 deletions.
49 changes: 27 additions & 22 deletions changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(.*)$/);
Expand Down Expand Up @@ -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;
Expand All @@ -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');
});
});

Expand All @@ -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) {
Expand All @@ -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;
};


Expand All @@ -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;
};


Expand Down
6 changes: 3 additions & 3 deletions changelog.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});

0 comments on commit 07a58dd

Please sign in to comment.