Skip to content

Commit

Permalink
Fixed Changelog generator task (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
matteofigus committed Apr 11, 2016
1 parent 9fc314b commit ee9a5bf
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions grunt-tasks/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,26 @@ module.exports = function(grunt){
_.forEach(commits, function(commit){
var commitMessages = commit.split('Merge pull request'),
isPr = commitMessages.length > 1,
isSquashedPr = !!commit.match(/(.*?)\(#(.*?)\)\n(.*?)/g);
isSquashedPr = !!commit.match(/(.*?)\(#(.*?)\)\n(.*?)/g),
commitMessage,
prNumber;

if(isPr){
var split = commitMessages[1].split('from'),
prNumber = split[0].trim().replace('#', ''),
branchName = split[1].trim().split(' ')[0].trim(),
commitMessage = split[1].replace(branchName, '').trim();
branchName = split[1].trim().split(' ')[0].trim();

prNumber = split[0].trim().replace('#', '');
commitMessage = split[1].replace(branchName, '').trim();

result.push(format('- [#{0}](https://github.com/opentable/oc/pull/{0}) {1}', prNumber, commitMessage));
} else if(isSquashedPr){
var lines = commit.split('\n'),
commitLine = lines[4],
prNumberStartIndex = commitLine.lastIndexOf(' ('),
prNumberEndIndex = commitLine.lastIndexOf(')'),
prNumber = commitLine.substr(prNumberStartIndex + 3, prNumberEndIndex - prNumberStartIndex - 3),
commitMessage = commitLine.substr(0, prNumberStartIndex).trim();
prNumberEndIndex = commitLine.lastIndexOf(')');

prNumber = commitLine.substr(prNumberStartIndex + 3, prNumberEndIndex - prNumberStartIndex - 3);
commitMessage = commitLine.substr(0, prNumberStartIndex).trim();

result.push(format('- [#{0}](https://github.com/opentable/oc/pull/{0}) {1}', prNumber, commitMessage));
}
Expand Down

0 comments on commit ee9a5bf

Please sign in to comment.