From 02fea7e898f58b58af0c258c81721c4e1a1eec40 Mon Sep 17 00:00:00 2001 From: Roman Isko Date: Tue, 7 Apr 2020 11:30:45 +0300 Subject: [PATCH] Refactor parse attachments. Rename field --- README.md | 2 +- action.yml | 2 +- main.js | 14 ++------------ 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index e59041d4..2d88f9a1 100644 --- a/README.md +++ b/README.md @@ -22,5 +22,5 @@ An action that simply sends a mail to multiple recipients. # Optional content type (defaults to text/plain): content_type: text/html # Optional attachments - attach_files: attachments.zip,git.diff,./dist/static/main.js + attachments: attachments.zip,git.diff,./dist/static/main.js ``` diff --git a/action.yml b/action.yml index 1e1a5e69..539a44f1 100644 --- a/action.yml +++ b/action.yml @@ -33,7 +33,7 @@ inputs: description: Content-Type HTTP header (text/html or text/plain) required: false default: text/plain - attach_files: + attachments: description: File paths (separated with comma) that will be added to mail message attachments required: false runs: diff --git a/main.js b/main.js index eb54f673..ea67acd9 100644 --- a/main.js +++ b/main.js @@ -19,16 +19,6 @@ function get_from(from, username) { return `"${from}" <${username}>` } -function get_attachments(attach_files) { - attach_files = attach_files.split(',') - let attachments = [] - for (const attach_file of attach_files) { - attachments.push({path: attach_file}) - } - - return attachments -} - async function main() { try { const server_address = core.getInput("server_address", { required: true }) @@ -40,7 +30,7 @@ async function main() { const to = core.getInput("to", { required: true }) const from = core.getInput("from", { required: true }) const content_type = core.getInput("content_type", { required: true }) - const attach_files = core.getInput("attach_files", { required: false }) + const attachments = core.getInput("attachments", { required: false }) const transport = nodemailer.createTransport({ host: server_address, @@ -58,7 +48,7 @@ async function main() { subject: subject, text: content_type != "text/html" ? get_body(body) : undefined, html: content_type == "text/html" ? get_body(body) : undefined, - attachments: attach_files ? get_attachments(attach_files) : undefined + attachments: attachments ? attachments.split(',').map(f => ({ path: f.trim() })) : undefined }) console.log(info)