React on push;
This commit is contained in:
parent
88cdc57e54
commit
37cc889d64
39
index.js
39
index.js
@ -19,9 +19,48 @@ var app = express();
|
||||
app.use(bodyParser.json()); // for parsing application/json
|
||||
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
|
||||
|
||||
function formatCommit(commit) {
|
||||
return commit.message + ' ' + commit.url;
|
||||
}
|
||||
|
||||
var handlers = {
|
||||
|
||||
push: function(body) {
|
||||
var user = body.user_name;
|
||||
var repoName = body.repository.name;
|
||||
var commits = body.commits;
|
||||
|
||||
var msg = ['push on ' + repoName + ': ' + user + ' pushed ' + commits.length + ' commits.'];
|
||||
|
||||
if (commits.length < 4) {
|
||||
msg = msg.concat(commits.map(formatCommit));
|
||||
} else {
|
||||
msg.push(formatCommit(commits[0]));
|
||||
msg.push('...');
|
||||
msg.push(formatCommit(commits[commits.length - 1]));
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
app.post('/', function(req, res) {
|
||||
var body = req.body || {};
|
||||
|
||||
var msgs = null;
|
||||
if (body.object_kind && handlers[body.object_kind])
|
||||
msgs = handlers[body.object_kind](body);
|
||||
|
||||
if (msgs) {
|
||||
if (msgs instanceof Array) {
|
||||
for (var i = 0; i < msgs.length; i++)
|
||||
say(config.channels, msgs[i]);
|
||||
} else {
|
||||
say(config.channels, msgs);
|
||||
}
|
||||
}
|
||||
|
||||
res.sendStatus(200);
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user