Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bin/changelog to deal with cherry-picked commits #3590

Merged
merged 1 commit into from
Jul 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 'data',
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/data/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