This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8594038
commit 3ba145f
Showing
5 changed files
with
99 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const chalk = require('chalk') | ||
const inquirer = require('inquirer') | ||
const nodemailer = require('nodemailer') | ||
|
||
const notifications = [ | ||
{ | ||
subject: 'Reminder: production changes', | ||
message: `It is important to remember that changes that have even the slightest chance of causing errors, should not be run directly on a production server (at least without testing somewhere else first). | ||
This includes changes such as: | ||
- updating plugins | ||
- changing config | ||
- etc.`, | ||
} | ||
] | ||
|
||
module.exports = (team, email) => { | ||
if (team.length) { | ||
inquirer | ||
.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'name', | ||
message: 'Who would you like to notify?', | ||
choices: team.map(({ name }) => name), | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'service', | ||
message: 'How would you like to notify them?', | ||
choices: [ 'Email' ], | ||
}, | ||
{ | ||
type: 'list', | ||
name: 'subject', | ||
message: 'What nofification would you like to send?', | ||
choices: notifications.map(({ subject }) => subject), | ||
} | ||
]) | ||
.then(({ name, service, subject }) => { | ||
console.log(chalk.dim(`Sending notification to ${name}...`)) | ||
|
||
const mailgun = email[0] | ||
const notification = notifications.filter(n => n.subject === subject)[0] | ||
const to = team.filter(m => m.name === name)[0].email | ||
|
||
const transporter = nodemailer.createTransport({ | ||
host: mailgun.host, | ||
port: mailgun.ports[0], | ||
secure: false, | ||
auth: { | ||
user: mailgun.user, | ||
pass: mailgun.password, | ||
}, | ||
}) | ||
|
||
const options = { | ||
from: '"S8 bot 🤖" <[email protected]>', | ||
to, | ||
subject: notification.subject, | ||
text: `Hi ${name}! | ||
${notification.message} | ||
- | ||
❤️ | ||
S8 bot 🤖`, | ||
} | ||
|
||
transporter.sendMail(options, (err, info) => { | ||
if (err) { | ||
return console.error(err) | ||
} | ||
|
||
console.log(chalk.bold.green(`Notification sent!`)) | ||
}) | ||
}) | ||
} else { | ||
console.log(`${chalk.bold.red('No team members to notify.')}`) | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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