Make the bot less verbose; fixes #11

- Send only one line per change;
- Add more precise messages for merge requests;
This commit is contained in:
Benjamin Bouvier 2016-08-16 14:53:05 +02:00
parent 05e1f02af7
commit 416bda36e0

View File

@ -26,6 +26,8 @@ var client = new irc.Client(config.server, config.nick, {
retryDelay: 120000
});
var mergeRequests = {};
var app = express();
app.use(bodyParser.json()); // for parsing application/json
@ -57,21 +59,21 @@ var handlers = {
var branchName = body.ref.replace('refs/heads/', '');
var msg = [];
var msg = null;
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);
msg = projectName + ': ' + user + ' ' + action + ' branch ' + branchName;
say(msg);
} else {
var maybeS = numCommits === 1 ? '' : 's';
msg.push('push on ' + projectName + '@' + branchName + ': ' + user + ' pushed ' + commits.length + ' commit' + maybeS + '.');
var lastCommit = commits[0];
var lastCommit = commits[commits.length - 1];
var lastCommitMessage = lastCommit.message.trim().split('\n')[0].trim();
shortenURL(lastCommit.url, function(shortUrl) {
msg.push('last commit: ' + lastCommit.message.trim() + ' : ' + shortUrl);
msg = 'push on ' + projectName + '@' + branchName + ' (by ' + user + '): ' +
commits.length + ' commit' + maybeS + ' (last: ' + lastCommitMessage + ') ' + shortUrl;
say(msg);
});
}
@ -83,7 +85,7 @@ var handlers = {
var issue = body.object_attributes;
var issueNumber = issue.iid;
var issueTitle = issue.title;
var issueTitle = issue.title.trim();
var issueState = issue.state;
var url = issue.url;
@ -92,9 +94,8 @@ var handlers = {
return;
shortenURL(url, function(shortUrl) {
var msg = [projectName + ': issue #' + issueNumber + ' has changed state ("' + issueState + '")'];
msg.push(issueTitle.trim() + ' ' + shortUrl);
say(msg)
var msg = projectName + ': issue #' + issueNumber + ' ("' + issueTitle + '") changed state ("' + issueState + '") ' + shortUrl;
say(msg);
});
},
@ -109,13 +110,24 @@ var handlers = {
var to = request.target_branch;
var id = request.iid;
var title = request.title;
var title = request.title.trim();
var url = request.url;
var state = request.state;
var assignee_id = request.assignee_id;
mergeRequests[id] = mergeRequests[id] || {};
var formerAssignee_id = mergeRequests[id].assignee_id;
mergeRequests[id].assignee_id = assignee_id;
// Abort if just the assignee changed;
if (typeof formerAssignee_id !== 'undefined' && assignee_id !== formerAssignee_id)
return;
shortenURL(url, function(shortUrl) {
var msg = [projectName + ': merge request (' + from + ':' + to + ') #' + id + ' has changed state ("' + state + '")'];
msg.push(title.trim() + ' ' + shortUrl);
var msg = projectName + ': merge request (' + from + '->' + to + ': ' + title + ') ' +
'#' + id + ' changed state ("' + state + '"): ' + shortUrl;
say(msg);
});
},
@ -131,10 +143,9 @@ var handlers = {
var projectName = body.project_name;
var stage = body.build_stage;
var msg = [];
msg.push(projectName + ': build #' + id + ' (' + stage + ') changed status: ' + status);
var msg = projectName + ': build #' + id + ' (' + stage + ') changed status: ' + status;
if (isFinished)
msg.push('build finished in ' + duration + ' seconds. ');
msg += ' (finished in ' + duration + ' seconds.)';
say(msg);
}