Mail notification implemented

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 11 years ago
parent 1137e217c8
commit 33d2cd3c92
  1. 26
      BuildServer/lib/builder.js
  2. 12
      BuildServer/lib/mail-sender.js
  3. 3
      BuildServer/package.json

@ -6,6 +6,7 @@ var async = require('async');
var request = require('request'); var request = require('request');
var gitLoader = require('./git-loader'); var gitLoader = require('./git-loader');
var processor = require('./task-processor'); var processor = require('./task-processor');
var mailSender = require('./mail-sender');
var settings = require('../settings'); var settings = require('../settings');
var notifyStatus = function (options, callback) { var notifyStatus = function (options, callback) {
@ -70,6 +71,8 @@ var build = function (options, callback) {
fs.writeFile(release + "/report.json", JSON.stringify({err: err, result: result}), function (writeErr) { fs.writeFile(release + "/report.json", JSON.stringify({err: err, result: result}), function (writeErr) {
statusQueue.push(function (callback) { statusQueue.push(function (callback) {
async.parallel([
function (callback) {
notifyStatus({ notifyStatus({
state: err ? "error" : "success", state: err ? "error" : "success",
description: errorMessage || warnMessage || infoMessage || "Success", description: errorMessage || warnMessage || infoMessage || "Success",
@ -77,6 +80,21 @@ var build = function (options, callback) {
reponame: reponame, reponame: reponame,
hash: rev hash: rev
}, callback); }, callback);
},
function (callback) {
mailSender.send({
from: 'Micro Build Server <test@example.com>',
to: '"Receiver Name" <test@example.com>',
subject: (err ? "Build failed for " : "Successfully built ") + owner + "/" + reponame + "/" + branch,
headers: {
'X-Laziness-level': 1000
},
text: ("Build status URL: https://mbs.pos/status/" + owner + "/" + reponame + "/" + rev + "\r\n\r\n") +
(err ? ("Error message: " + err + "\r\n\r\n") : "") +
((!result.messages || !result.messages.$allMessages) ? JSON.stringify(result, null, 4) : result.messages.$allMessages.map(function (msg) { return msg.prefix + "\t" + msg.message; }).join("\r\n"))
}, callback);
}
], callback);
}); });
if (writeErr) { if (writeErr) {
@ -91,7 +109,7 @@ var build = function (options, callback) {
local: local, local: local,
branch: branch, branch: branch,
hash: rev, hash: rev,
exported: tmp + "/code", exported: tmp + "/code"
}, function(err) { }, function(err) {
if (err) { if (err) {
console.log(err); console.log(err);
@ -110,9 +128,9 @@ var build = function (options, callback) {
var task; var task;
try { try {
task = JSON.parse(data); task = JSON.parse(data);
} catch(err) { } catch(ex) {
console.log("Malformed data: " + data); console.log("Malformed data: " + data);
return done(err, "MBSMalformed"); return done(ex, "MBSMalformed");
} }
processor.processTask(task, { processor.processTask(task, {
@ -133,6 +151,6 @@ var build = function (options, callback) {
}); });
}); });
}); });
} };
exports.build = build; exports.build = build;

@ -0,0 +1,12 @@
"use strict";
var nodemailer = require('nodemailer');
var settings = require('../settings');
exports.send = function (message, callback) {
var transport = nodemailer.createTransport("SMTP", settings.smtp);
transport.sendMail(message, function(err, result) {
transport.close();
callback(err, result);
});
};

@ -12,6 +12,7 @@
"fs-extra": "~0.8.1", "fs-extra": "~0.8.1",
"git-node": "~0.1.1", "git-node": "~0.1.1",
"request": "~2.27.0", "request": "~2.27.0",
"glob": "~3.2.7" "glob": "~3.2.7",
"nodemailer": "~0.6.0"
} }
} }

Loading…
Cancel
Save