diff --git a/index.js b/index.js index ae28379..ffd8105 100644 --- a/index.js +++ b/index.js @@ -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;