From 35b2ac49860bcea8455509638809f31c5befe70c Mon Sep 17 00:00:00 2001 From: Nathan Dawson <43784056+Oatelaus@users.noreply.github.com> Date: Wed, 26 Jun 2024 15:12:37 +0100 Subject: [PATCH] import eta templates as javascript strings (#648) --- lib/{commentmessage.eta => commentmessage.js} | 10 ++++------ lib/{error.eta => error.js} | 3 ++- lib/settings.js | 8 +++++--- 3 files changed, 11 insertions(+), 10 deletions(-) rename lib/{commentmessage.eta => commentmessage.js} (84%) rename lib/{error.eta => error.js} (76%) diff --git a/lib/commentmessage.eta b/lib/commentmessage.js similarity index 84% rename from lib/commentmessage.eta rename to lib/commentmessage.js index 2a4e668e..93d97039 100644 --- a/lib/commentmessage.eta +++ b/lib/commentmessage.js @@ -1,6 +1,6 @@ -* Run on: `<%= new Date() %>` +module.exports = `* Run on: \` <%= new Date() %> \` -* Number of repos that were considered: `<%= Object.keys(it.reposProcessed).length %>` +* Number of repos that were considered: \`<%= Object.keys(it.reposProcessed).length %> \` ### Breakdown of changes | Repo <% Object.keys(it.changes).forEach(plugin => { %> | <%= plugin %> settings <% }) %> | @@ -19,7 +19,7 @@ ### Breakdown of errors <% if (Object.keys(it.errors).length === 0) { %> -`None` +\`None\` <% } else { %> <% Object.keys(it.errors).forEach(repo => { %> <%_= repo %>: @@ -28,6 +28,4 @@ <% }) %> <% }) %> -<% } %> - - +<% } %>` \ No newline at end of file diff --git a/lib/error.eta b/lib/error.js similarity index 76% rename from lib/error.eta rename to lib/error.js index 4bf6dee2..f268ac6c 100644 --- a/lib/error.eta +++ b/lib/error.js @@ -1,4 +1,4 @@ -Run on: `<%= new Date().toISOString() %>` +module.exports = `Run on: \`<%= new Date().toISOString() %>\` #### Breakdown of Errors | Owner| Repo | Plugin | Error @@ -9,3 +9,4 @@ Run on: `<%= new Date().toISOString() %>` <% }) -%> +` \ No newline at end of file diff --git a/lib/settings.js b/lib/settings.js index 21cac18b..961aa4c6 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -1,5 +1,7 @@ const path = require('path') const { Eta } = require('eta') +const commetMessageTemplate = require('./commentmessage') +const errorTemplate = require('./error') const Glob = require('./glob') const NopCommand = require('./nopcommand') const MergeDeep = require('./mergeDeep') @@ -103,7 +105,7 @@ class Settings { if (this.errors.length > 0) { conclusion = 'failure' summary = 'Safe-Settings finished with errors.' - details = await eta.render('./error', this.errors) + details = await eta.renderString(errorTemplate, this.errors) } // Use the latest commit to create the check against @@ -217,7 +219,7 @@ class Settings { ` - const commentmessage = await eta.render('./commentmessage', stats) + const renderedCommentMessage = await eta.renderString(commetMessageTemplate, stats) if (env.CREATE_PR_COMMENT === 'true') { const summary = ` @@ -262,7 +264,7 @@ ${this.results.reduce((x, y) => { completed_at: new Date().toISOString(), output: { title: error ? 'Safe-Settings Dry-Run Finished with Error' : 'Safe-Settings Dry-Run Finished with success', - summary: commentmessage.length > 55536 ? `${commentmessage.substring(0, 55536)}... (too many changes to report)` : commentmessage + summary: renderedCommentMessage.length > 55536 ? `${renderedCommentMessage.substring(0, 55536)}... (too many changes to report)` : renderedCommentMessage } }