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:
parent
05e1f02af7
commit
416bda36e0
43
index.js
43
index.js
@ -26,6 +26,8 @@ var client = new irc.Client(config.server, config.nick, {
|
|||||||
retryDelay: 120000
|
retryDelay: 120000
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var mergeRequests = {};
|
||||||
|
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
app.use(bodyParser.json()); // for parsing application/json
|
app.use(bodyParser.json()); // for parsing application/json
|
||||||
@ -57,21 +59,21 @@ var handlers = {
|
|||||||
|
|
||||||
var branchName = body.ref.replace('refs/heads/', '');
|
var branchName = body.ref.replace('refs/heads/', '');
|
||||||
|
|
||||||
var msg = [];
|
var msg = null;
|
||||||
if (!numCommits) {
|
if (!numCommits) {
|
||||||
// Special case: a branch was created or deleted.
|
// Special case: a branch was created or deleted.
|
||||||
var action = 'created';
|
var action = 'created';
|
||||||
if (body.after === '0000000000000000000000000000000000000000')
|
if (body.after === '0000000000000000000000000000000000000000')
|
||||||
action = 'deleted';
|
action = 'deleted';
|
||||||
msg.push(projectName + ': ' + user + ' ' + action + ' branch ' + branchName);
|
msg = projectName + ': ' + user + ' ' + action + ' branch ' + branchName;
|
||||||
say(msg);
|
say(msg);
|
||||||
} else {
|
} else {
|
||||||
var maybeS = numCommits === 1 ? '' : 's';
|
var maybeS = numCommits === 1 ? '' : 's';
|
||||||
msg.push('push on ' + projectName + '@' + branchName + ': ' + user + ' pushed ' + commits.length + ' commit' + maybeS + '.');
|
var lastCommit = commits[commits.length - 1];
|
||||||
|
var lastCommitMessage = lastCommit.message.trim().split('\n')[0].trim();
|
||||||
var lastCommit = commits[0];
|
|
||||||
shortenURL(lastCommit.url, function(shortUrl) {
|
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);
|
say(msg);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -83,7 +85,7 @@ var handlers = {
|
|||||||
|
|
||||||
var issue = body.object_attributes;
|
var issue = body.object_attributes;
|
||||||
var issueNumber = issue.iid;
|
var issueNumber = issue.iid;
|
||||||
var issueTitle = issue.title;
|
var issueTitle = issue.title.trim();
|
||||||
var issueState = issue.state;
|
var issueState = issue.state;
|
||||||
var url = issue.url;
|
var url = issue.url;
|
||||||
|
|
||||||
@ -92,9 +94,8 @@ var handlers = {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
shortenURL(url, function(shortUrl) {
|
shortenURL(url, function(shortUrl) {
|
||||||
var msg = [projectName + ': issue #' + issueNumber + ' has changed state ("' + issueState + '")'];
|
var msg = projectName + ': issue #' + issueNumber + ' ("' + issueTitle + '") changed state ("' + issueState + '") ' + shortUrl;
|
||||||
msg.push(issueTitle.trim() + ' ' + shortUrl);
|
say(msg);
|
||||||
say(msg)
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -109,13 +110,24 @@ var handlers = {
|
|||||||
var to = request.target_branch;
|
var to = request.target_branch;
|
||||||
|
|
||||||
var id = request.iid;
|
var id = request.iid;
|
||||||
var title = request.title;
|
var title = request.title.trim();
|
||||||
var url = request.url;
|
var url = request.url;
|
||||||
var state = request.state;
|
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) {
|
shortenURL(url, function(shortUrl) {
|
||||||
var msg = [projectName + ': merge request (' + from + ':' + to + ') #' + id + ' has changed state ("' + state + '")'];
|
var msg = projectName + ': merge request (' + from + '->' + to + ': ' + title + ') ' +
|
||||||
msg.push(title.trim() + ' ' + shortUrl);
|
'#' + id + ' changed state ("' + state + '"): ' + shortUrl;
|
||||||
say(msg);
|
say(msg);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -131,10 +143,9 @@ var handlers = {
|
|||||||
var projectName = body.project_name;
|
var projectName = body.project_name;
|
||||||
var stage = body.build_stage;
|
var stage = body.build_stage;
|
||||||
|
|
||||||
var msg = [];
|
var msg = projectName + ': build #' + id + ' (' + stage + ') changed status: ' + status;
|
||||||
msg.push(projectName + ': build #' + id + ' (' + stage + ') changed status: ' + status);
|
|
||||||
if (isFinished)
|
if (isFinished)
|
||||||
msg.push('build finished in ' + duration + ' seconds. ');
|
msg += ' (finished in ' + duration + ' seconds.)';
|
||||||
|
|
||||||
say(msg);
|
say(msg);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user