This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from cjsaylor/security-updates
Security updates
- Loading branch information
Showing
7 changed files
with
557 additions
and
796 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.