Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #26 from cjsaylor/security-updates
Browse files Browse the repository at this point in the history
Security updates
  • Loading branch information
cjsaylor authored Jul 30, 2018
2 parents 9f27da2 + 62da913 commit 4ebc1f8
Show file tree
Hide file tree
Showing 7 changed files with 557 additions and 796 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const OFF = 0;

module.exports = {
"env": {
"node": true
"node": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2017
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async function main() {
if (notifier.length() === 0) {
notifier.add(notifiers.console);
}
notifier.notifyAll(results);
await notifier.notifyAll(results);
} catch (e) {
console.error(e);
process.exit(1);
Expand Down
59 changes: 29 additions & 30 deletions lib/notifiers/email.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
var fs = require('fs');
var _ = require('lodash');
var P = require('bluebird');

var Email = module.exports = function (emailAddresses, replyTo, subjectTemplate = 'Drill Sergeant Stale Pull Request Report (<%= date %>)') {
var template = fs.readFileSync(__dirname + '/../../templates/email.html').toString();
this.emailAddresses = emailAddresses;
this.replyTo = replyTo;
this.compiledTemplate = _.template(template);
this.subjectTemplate = subjectTemplate;
this.client = require('nodemailer').mail;
};
module.exports = class Email {
constructor(emailAddresses, replyTo, subjectTemplate = 'Drill Sergeant Stale Pull Request Report (<%= date %>)') {
this.emailAddresses = emailAddresses;
this.replyTo = replyTo;
this.compiledTemplate = _.template(fs.readFileSync(__dirname + '/../../templates/email.html').toString());
this.subjectTemplate = subjectTemplate;
this.client = require('nodemailer').createTransport({
sendmail: true
});
}

Email.getSubjectDate = function() {
return new Date().toLocaleDateString();
};
getSubjectDate() {
return new Date().toLocaleDateString();
}

Email.prototype.setClient = function(client) {
this.client = client;
};
setClient(client) {
this.client = client;
}

Email.prototype.notify = function(repos) {
var escapePrTitle = function(pr) {
pr.title = _.escape(pr.title);
return pr;
};
var mapTitles = function(repo) {
repo.prs = repo.prs.map(escapePrTitle);
return repo;
};
var sendEmail = function() {
async notify(repos) {
const escapePrTitle = pr => Object.assign(pr, {
title: _.escape(pr.title)
});
const mappedRepos = repos.map(repo => Object.assign(repo, {
prs: repo.prs.map(escapePrTitle)
}));
const subject = _.template(this.subjectTemplate)({
date: Email.getSubjectDate()
date: this.getSubjectDate()
});
return this.client({
await this.client.sendMail({
from: this.replyTo,
to: this.emailAddresses,
subject: subject,
html: this.compiledTemplate({ repos: repos })
html: this.compiledTemplate({
repos: mappedRepos
})
});
}.bind(this);
return P.map(repos, mapTitles).then(sendEmail);
}
};
7 changes: 3 additions & 4 deletions lib/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ module.exports = class Notifier {
return this.notifiers.length;
}

notifyAll(repoData) {
this.notifiers.forEach(function (notifier) {
notifier.notify(repoData);
});
async notifyAll(repoData) {
let promises = this.notifiers.map(notifier => notifier.notify(repoData));
await Promise.all(promises);
}
};
Loading

0 comments on commit 4ebc1f8

Please sign in to comment.