From 6d664213c5eab467a8e5d96d82674b54e282b2e4 Mon Sep 17 00:00:00 2001 From: oleg Date: Sun, 5 Jul 2015 14:47:43 +0300 Subject: [PATCH] add mail notifier --- app.js | 1 + data/config.yaml | 8 ++++- data/projects/project1/config.yaml | 5 +-- lib/notifier/mail.js | 52 ++++++++++++++++++++++++++++++ package.json | 1 + 5 files changed, 64 insertions(+), 3 deletions(-) create mode 100644 lib/notifier/mail.js diff --git a/app.js b/app.js index f5a46b4..f9ccbc6 100644 --- a/app.js +++ b/app.js @@ -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()); }, diff --git a/data/config.yaml b/data/config.yaml index 3c30a60..2e7a034 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -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 diff --git a/data/projects/project1/config.yaml b/data/projects/project1/config.yaml index d71ab52..52b5cea 100644 --- a/data/projects/project1/config.yaml +++ b/data/projects/project1/config.yaml @@ -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 diff --git a/lib/notifier/mail.js b/lib/notifier/mail.js new file mode 100644 index 0000000..2492eae --- /dev/null +++ b/lib/notifier/mail.js @@ -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 %>
' + + '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 + ); +}; diff --git a/package.json b/package.json index a1689cd..942bc41 100644 --- a/package.json +++ b/package.json @@ -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"