Mail notification implemented

dependabot/npm_and_yarn/BuildServer/eslint-7.2.0
Inga 🏳‍🌈 11 years ago
parent 1137e217c8
commit 33d2cd3c92
  1. 40
      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 gitLoader = require('./git-loader');
var processor = require('./task-processor');
var mailSender = require('./mail-sender');
var settings = require('../settings');
var notifyStatus = function (options, callback) {
@ -70,13 +71,30 @@ var build = function (options, callback) {
fs.writeFile(release + "/report.json", JSON.stringify({err: err, result: result}), function (writeErr) {
statusQueue.push(function (callback) {
notifyStatus({
state: err ? "error" : "success",
description: errorMessage || warnMessage || infoMessage || "Success",
owner: owner,
reponame: reponame,
hash: rev
}, callback);
async.parallel([
function (callback) {
notifyStatus({
state: err ? "error" : "success",
description: errorMessage || warnMessage || infoMessage || "Success",
owner: owner,
reponame: reponame,
hash: rev
}, 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) {
@ -91,7 +109,7 @@ var build = function (options, callback) {
local: local,
branch: branch,
hash: rev,
exported: tmp + "/code",
exported: tmp + "/code"
}, function(err) {
if (err) {
console.log(err);
@ -110,9 +128,9 @@ var build = function (options, callback) {
var task;
try {
task = JSON.parse(data);
} catch(err) {
} catch(ex) {
console.log("Malformed data: " + data);
return done(err, "MBSMalformed");
return done(ex, "MBSMalformed");
}
processor.processTask(task, {
@ -133,6 +151,6 @@ var build = function (options, callback) {
});
});
});
}
};
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",
"git-node": "~0.1.1",
"request": "~2.27.0",
"glob": "~3.2.7"
"glob": "~3.2.7",
"nodemailer": "~0.6.0"
}
}

Loading…
Cancel
Save