Skip to content

Commit

Permalink
Merge pull request #11732 from rwjblue/make-changelog-script-work-for…
Browse files Browse the repository at this point in the history
…-cherry-picks

Update bin/changelog to deal with cherry-picked commits.
  • Loading branch information
rwjblue committed Jul 14, 2015
2 parents a32ee08 + fd153a6 commit 6587513
Showing 1 changed file with 45 additions and 19 deletions.
64 changes: 45 additions & 19 deletions bin/changelog
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,80 @@ var EOL = require('os').EOL;
var RSVP = require('rsvp');
var Promise = RSVP.Promise;
var GitHubApi = require('github');
var execSync = require('child_process').execSync;

var github = new GitHubApi({version: '3.0.0'});
var compareCommits = RSVP.denodeify(github.repos.compareCommits);
var currentVersion = process.env.PRIOR_VERSION;
var head = process.env.HEAD || 'master';

compareCommits({
user: 'emberjs',
repo: 'ember.js',
base: currentVersion,
head: 'master'
head: head
})
.then(processPages)
.then(console.log)
.catch(function(err) {
console.error(err);
})

function processPages(res) {
var contributions = res.commits.map(function(commitInfo) {
return commitInfo.commit.message
function getCommitMessage(commitInfo) {
var message = commitInfo.commit.message;

if (message.indexOf('cherry picked from commit') > -1) {
var originalCommit = message.split('cherry picked from commit ').slice(-1); // find the last instance of `cherry picked from`
originalCommit = originalCommit[0].slice(0, -1); // remove the trailing `)`

try {
// command from http://stackoverflow.com/questions/8475448/find-merge-commit-which-include-a-specific-commit
message = execSync('commit=$((git rev-list ' + originalCommit + '..origin/master --ancestry-path | cat -n; git rev-list ' + originalCommit + '..origin/master --first-parent | cat -n) | sort -k2 | uniq -f1 -d | sort -n | tail -1 | cut -f2) && git show --format="%s\n\n%b" $commit', { encoding: 'utf8' });
} catch(e) { }
}

return message;
}

}).filter(function(message) {
return message.indexOf('Merge pull request #') > -1;
}).map(function(message) {
var numAndAuthor = message.match(/#(\d+) from (.*)\//).slice(1,3);
var title = message.split('\n\n')[1];
function processPages(res) {
var contributions = res.commits.filter(function(commitInfo) {
var message = commitInfo.commit.message;

return {
number: +numAndAuthor[0],
author: numAndAuthor[1],
title: title
return message.indexOf('Merge pull request #') > -1 || message.indexOf('cherry picked from') > -1;
}).map(function(commitInfo) {
var message = getCommitMessage(commitInfo);
var match = message.match(/#(\d+) from (.*)\//);
var result = {
sha: commitInfo.sha
};

if (match) {
var numAndAuthor = match.slice(1, 3);

result.number =numAndAuthor[0];
result.title = message.split('\n\n')[1];
} else {
result.title = message.split('\n\n')[0];
}

return result;
}).sort(function(a, b) {
return a.number > b.number;
}).map(function(pr) {
var link = '[#' + pr.number + ']' +
'(https://github.com/emberjs/ember.js/pull/' + pr.number + ')';
var title = pr.title;
var author = '[@' + pr.author + ']' +
'(https://github.com/' + pr.author +')';
var link;
if (pr.number) {
link = '[#' + pr.number + ']' + '(https://github.com/emberjs/ember.js/pull/' + pr.number + ')';
} else {
link = '[' + pr.sha.slice(0, 8) + '](https://github.com/emberjs/ember.js/commit/' + pr.sha + ')';
}

return '- ' + link + ' ' + title + ' ' + author;
return '- ' + link + ' ' + title;
}).join('\n');

if (github.hasNextPage(res)) {
return github.getNextPage(res)
.then(function(nextPage) {
console.log('getting next page!');
contributions += processPages(nextPage);
});
} else {
Expand Down

0 comments on commit 6587513

Please sign in to comment.