Fixes #4: Add branch name in push message, tidy up push hook;

This commit is contained in:
Benjamin Bouvier 2016-06-24 01:28:27 +02:00
parent 9772ad859f
commit 0f103fabfe

View File

@ -28,15 +28,28 @@ var handlers = {
push: function(body) {
var user = body.user_name;
var projectName = body.project.name;
var commits = body.commits;
var numCommits = body.total_commits_count;
var msg = ['push on ' + projectName + ': ' + user + ' pushed ' + commits.length + ' commits.'];
var branchName = body.ref.replace('refs/heads/', '');
if (commits.length < 4) {
msg = msg.concat(commits.map(formatCommit));
var msg = [];
if (!numCommits) {
// Special case: a branch was created or deleted.
var action = 'created';
if (body.after === '0000000000000000000000000000000000000000')
action = 'deleted';
msg.push(projectName + ': ' + user + ' ' + action + ' branch ' + branchName);
} else {
msg.push(formatCommit(commits[0]) + ' ...');
msg.push(formatCommit(commits[commits.length - 1]));
var maybeS = numCommits === 1 ? '' : 's';
msg.push('push on ' + projectName + '@' + branchName + ': ' + user + ' pushed ' + commits.length + ' commit' + maybeS + '.');
if (numCommits < 4) {
msg = msg.concat(commits.map(formatCommit));
} else {
msg.push(formatCommit(commits[0]) + ' ...');
msg.push(formatCommit(commits[commits.length - 1]));
}
}
return msg;