11const fs = require ( 'fs' ) ;
22const axios = require ( 'axios' ) ;
33const showdown = require ( 'showdown' ) ;
4- const Mailgun = require ( 'mailgun.js' ) ;
5-
6- const mailgun = new Mailgun ( { apiKey : process . env . MAILGUN_API_TOKEN , domain : process . env . MAILGUN_EMAIL_DOMAIN } ) ;
4+ const Mailgun = require ( 'mailgun-js' ) ;
75
86async function prepareMessage ( recipients , lists ) {
97 const { repository, release } = JSON . parse ( fs . readFileSync ( process . env . GITHUB_EVENT_PATH , 'utf8' ) ) ;
@@ -27,11 +25,11 @@ async function prepareMessage(recipients, lists) {
2725
2826 const sender = process . env . RELEASE_SENDER_EMAIL ;
2927
30- if ( releaseRegex == null || new RegExp ( releaseRegex ) . match ( releaseVersion ) != null ) {
28+ if ( releaseRegex == null || new RegExp ( releaseRegex ) . test ( releaseVersion ) != null ) {
3129 return {
3230 from : sender ,
33- to : lists ,
34- bcc : recipients ,
31+ to : recipients ,
32+ bcc : lists ,
3533 subject : subject ,
3634 html : releaseBody ,
3735 } ;
@@ -43,6 +41,9 @@ async function run(recipientsUrl, distributionLists) {
4341 const { data } = await axios . get ( recipientsUrl ) ;
4442 const recipients = data . split ( / \r \n | \n | \r / ) ;
4543 const lists = distributionLists ? distributionLists . split ( ',' ) : [ ] ;
44+
45+ const mailgun = new Mailgun ( { apiKey : process . env . MAILGUN_API_TOKEN , domain : process . env . MAILGUN_EMAIL_DOMAIN } ) ;
46+
4647 const message = await prepareMessage ( recipients , lists ) ;
4748 if ( message != false ) {
4849 await mailgun . messages ( ) . send ( message , function ( err , body ) {
@@ -60,7 +61,6 @@ async function run(recipientsUrl, distributionLists) {
6061/**
6162 * Run
6263 */
63- setCredentials ( ) ;
6464run ( process . env . RELEASE_RECIPIENTS_URL , process . env . RELEASE_DISTRIBUTION_LISTS )
6565 . catch ( ( error ) => {
6666 console . error ( error ) ;
0 commit comments