add mail notifier

This commit is contained in:
oleg 2015-07-05 14:47:43 +03:00
parent 6180f2cde4
commit 6d664213c5
5 changed files with 64 additions and 3 deletions

1
app.js
View File

@ -64,6 +64,7 @@ Steppy(
// register plugins
require('./lib/reader/yaml').register(app);
require('./lib/notifier/console').register(app);
require('./lib/notifier/mail').register(app);
reader.load(app.config.paths.data, 'config', this.slot());
},

View File

@ -3,7 +3,13 @@ nodes:
- type: local
maxExecutorsCount: 2
notify: {}
notify:
mail:
host: smtp.gmail.com
port: 587
auth:
user: bot.nci@gmail.com
pass: pass
httpApi:
host: 127.0.0.1

View File

@ -9,13 +9,14 @@ catchRev:
notify:
on:
# - done
- done
# - error
- change
to:
console:
# email:
# mail:
# - oleg.korobenko@gmail.com
# - oleg.poligon@gmail.com
# jabber:
# - oleg.korobenko@gmail.com

52
lib/notifier/mail.js Normal file
View File

@ -0,0 +1,52 @@
'use strict';
var BaseNotifier = require('./base').Notifier,
inherits = require('util').inherits,
Steppy = require('twostep').Steppy,
_ = require('underscore'),
nodemailer = require('nodemailer');
function Notifier() {
}
inherits(Notifier, BaseNotifier);
exports.register = function(app) {
app.lib.notifier.register('mail', Notifier);
};
Notifier.prototype.init = function(params, callback) {
this.transport = nodemailer.createTransport(params);
callback();
};
Notifier.prototype._subjectTemplate = _(
'<%= build.project.name %> build #<%= build.number %> ' +
'is <%= build.status %>'
).template();
Notifier.prototype._bodyTemplate = _(
'<%= build.project.name %> build #<%= build.number %> status: ' +
'<%= build.status %><br>' +
'Current revision is: ' +
'<%= build.scm.rev.author %>: <%= build.scm.rev.comment %>'
).template();
Notifier.prototype.send = function(params, callback) {
var self = this,
build = params.build;
Steppy(
function() {
var subject = self._subjectTemplate(params),
body = self._bodyTemplate(params);
self.transport.sendMail({
subject: subject,
html: body,
to: params.build.project.notify.to.mail.join(',')
}, this.slot());
},
callback
);
};

View File

@ -34,6 +34,7 @@
"js-yaml": "3.3.1",
"nlevel": "1.0.2",
"node-static": "0.7.6",
"nodemailer": "1.4.0",
"socket.io": "1.3.5",
"twostep": "0.4.1",
"underscore": "1.8.2"