Skip to content

Commit

Permalink
chore(changelog): Add breaking changes section
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Apr 16, 2013
1 parent 9e6e969 commit 3a5785c
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
44 changes: 30 additions & 14 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,34 +296,50 @@ module.exports = function(grunt) {
var done = grunt.task.current.async();
var child = grunt.util.spawn({
cmd:process.platform === 'win32' ? 'git.cmd' : 'git',
args:['log', changeFrom + '..' + changeTo, '--oneline']
args: [
'log',
changeFrom + '..' + changeTo,
'--format=%H%n%s%n%b%n==END=='
]
}, function (err, result, code) {

var changelog = {
chore: {}, demo: {}, docs: {}, feat: {}, fix: {}, refactor: {}, style: {}, test: {}
};
var changelog = {};
function addChange(changeType, component, change) {
if (!changelog[changeType]) {
changelog[changeType] = {};
}
if (!changelog[changeType][component]) {
changelog[changeType][component] = [];
}
changelog[changeType][component].push(change);
}

var COMMIT_MSG_REGEXP = /^(chore|demo|docs|feat|fix|refactor|style|test)\((.+)\):? (.+)$/;
var gitlog = ('' + result).split('\n').reverse();
var gitlog = result.toString().split('\n==END==\n').reverse();

if (code) {
grunt.log.error(err);
done(false);
} else {

gitlog.forEach(function (logItem) {
var sha1 = logItem.slice(0, 7);
var fullMsg = logItem.slice(8);
var lines = logItem.split('\n');
var sha1 = lines.shift().substr(0,8); //Only first 7 of sha1
var subject = lines.shift();

var msgMatches = fullMsg.match(COMMIT_MSG_REGEXP);
var msgMatches = subject.match(COMMIT_MSG_REGEXP);
var changeType = msgMatches[1];
var directive = msgMatches[2];
var directiveMsg = msgMatches[3];

if (!changelog[changeType][directive]) {
changelog[changeType][directive] = [];
var component = msgMatches[2];
var componentMsg = msgMatches[3];

var breaking = logItem.match(/BREAKING CHANGE:([\s\S]*)/);
if (breaking) {
addChange('breaking', component, {
sha1: sha1,
msg: breaking[1]
});
}
changelog[changeType][directive].push({sha1:sha1, msg:directiveMsg});
addChange(changeType, component, {sha1:sha1, msg:componentMsg});
});

console.log(grunt.template.process(grunt.file.read('misc/changelog.tpl.md'), {data: {
Expand Down
32 changes: 24 additions & 8 deletions misc/changelog.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,27 @@

## Features

<% _(changelog.feat).forEach(function(changes, directive) { %>- **<%= directive%>:**
<% changes.forEach(function(change) { %> - <%= change.msg%> ([<%= change.sha1%>](https://github.com/angular-ui/bootstrap/commit/<%= change.sha1%>))
<% }) %><% }) %>
## Bug fixes

<% _(changelog.fix).forEach(function(changes, directive) { %>- **<%= directive%>:**
<% changes.forEach(function(change) { %> - <%= change.msg%> ([<%= change.sha1%>](https://github.com/angular-ui/bootstrap/commit/<%= change.sha1%>))
<% }) %><% }) %>
<% _(changelog.feat).forEach(function(changes, component) { %>
- **<%= component%>:**
<% changes.forEach(function(change) { %>
- <%= change.msg%> ([<%= change.sha1%>](https://github.com/angular-ui/bootstrap/commit/<%= change.sha1%>))
<% }) %>
<% }) %>

## Bug Fixes

<% _(changelog.fix).forEach(function(changes, component) { %>
- **<%= component%>:**
<% changes.forEach(function(change) { %>
- <%= change.msg%> ([<%= change.sha1%>](https://github.com/angular-ui/bootstrap/commit/<%= change.sha1%>))
<% }) %>
<% }) %>

## Breaking Changes

<% _(changelog.breaking).forEach(function(changes, component) { %>
- **<%= component%>:**
<% changes.forEach(function(change) { %>
<%= change.msg%>
<% }) %>
<% }) %>

0 comments on commit 3a5785c

Please sign in to comment.