From d4b4fe8144c28ed0b6c489de2064ba72f090eabb Mon Sep 17 00:00:00 2001 From: Roman Isko Date: Tue, 7 Apr 2020 09:46:19 +0300 Subject: [PATCH 1/6] Add possibility to attach a file to mail --- action.yml | 3 +++ main.js | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/action.yml b/action.yml index 116f0c25..d011e2c1 100644 --- a/action.yml +++ b/action.yml @@ -33,6 +33,9 @@ inputs: description: Content-Type HTTP header (text/html or text/plain) required: false default: text/plain + attach_file: + description: File path that will be added to mail message attachments + required: false runs: using: node12 main: main.js diff --git a/main.js b/main.js index 4ea3b848..4d21a0e4 100644 --- a/main.js +++ b/main.js @@ -30,6 +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_file = core.getInput("attach_file", { required: false }) const transport = nodemailer.createTransport({ host: server_address, @@ -47,6 +48,9 @@ async function main() { subject: subject, text: content_type != "text/html" ? get_body(body) : undefined, html: content_type == "text/html" ? get_body(body) : undefined, + attachments: { + path: attach_file + } }) console.log(info) From a5cba0b6c1f47a99f3425f08d8f4e1fc2630eaa0 Mon Sep 17 00:00:00 2001 From: Roman Isko Date: Tue, 7 Apr 2020 09:50:06 +0300 Subject: [PATCH 2/6] Do not add attachment in case it's not specified --- main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.js b/main.js index 4d21a0e4..d758ee52 100644 --- a/main.js +++ b/main.js @@ -48,9 +48,9 @@ async function main() { subject: subject, text: content_type != "text/html" ? get_body(body) : undefined, html: content_type == "text/html" ? get_body(body) : undefined, - attachments: { + attachments: attach_file ? { path: attach_file - } + } : undefined }) console.log(info) From 1733012f4d5ee60dacf8f018f542c6d4e3534537 Mon Sep 17 00:00:00 2001 From: Roman Isko Date: Tue, 7 Apr 2020 09:55:36 +0300 Subject: [PATCH 3/6] Add example in doc --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 28e5c079..1a2f66dc 100644 --- a/README.md +++ b/README.md @@ -21,4 +21,6 @@ An action that simply sends a mail to multiple recipients. from: Luke Skywalker # # Optional content type (defaults to text/plain): content_type: text/html + # Optional single file attachment + attach_file: attachments.zip ``` From c2ca628a67b76ba73ba46d0b123575c067b597da Mon Sep 17 00:00:00 2001 From: Roman Isko Date: Tue, 7 Apr 2020 11:14:31 +0300 Subject: [PATCH 4/6] Attach multiple files to mail message --- README.md | 4 ++-- action.yml | 4 ++-- main.js | 16 ++++++++++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1a2f66dc..e59041d4 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,6 @@ An action that simply sends a mail to multiple recipients. from: Luke Skywalker # # Optional content type (defaults to text/plain): content_type: text/html - # Optional single file attachment - attach_file: attachments.zip + # Optional attachments + attach_files: attachments.zip,git.diff,./dist/static/main.js ``` diff --git a/action.yml b/action.yml index d011e2c1..1e1a5e69 100644 --- a/action.yml +++ b/action.yml @@ -33,8 +33,8 @@ inputs: description: Content-Type HTTP header (text/html or text/plain) required: false default: text/plain - attach_file: - description: File path that will be added to mail message attachments + attach_files: + description: File paths (separated with comma) that will be added to mail message attachments required: false runs: using: node12 diff --git a/main.js b/main.js index d758ee52..eb54f673 100644 --- a/main.js +++ b/main.js @@ -19,6 +19,16 @@ 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 }) @@ -30,7 +40,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_file = core.getInput("attach_file", { required: false }) + const attach_files = core.getInput("attach_files", { required: false }) const transport = nodemailer.createTransport({ host: server_address, @@ -48,9 +58,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_file ? { - path: attach_file - } : undefined + attachments: attach_files ? get_attachments(attach_files) : undefined }) console.log(info) From 02fea7e898f58b58af0c258c81721c4e1a1eec40 Mon Sep 17 00:00:00 2001 From: Roman Isko Date: Tue, 7 Apr 2020 11:30:45 +0300 Subject: [PATCH 5/6] 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) From 3eb5d684cd897b8dd60c8e18cfca8b4e38ad639a Mon Sep 17 00:00:00 2001 From: Roman Isko Date: Tue, 7 Apr 2020 11:32:14 +0300 Subject: [PATCH 6/6] Apply field description suggested by author --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 539a44f1..4fc67af9 100644 --- a/action.yml +++ b/action.yml @@ -34,7 +34,7 @@ inputs: required: false default: text/plain attachments: - description: File paths (separated with comma) that will be added to mail message attachments + description: Files that will be added to mail message attachments (separated with comma) required: false runs: using: node12