From 1d49a01e7c7ef698905278d2895425182d53e6c9 Mon Sep 17 00:00:00 2001 From: Shohei Ueda <30958501+peaceiris@users.noreply.github.com> Date: Wed, 25 Nov 2020 19:15:35 +0900 Subject: [PATCH] feat: Support comment header and footer (#327) Pull Request for Issue #318 --- src/main.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main.ts b/src/main.ts index 50345d8b..525e43af 100644 --- a/src/main.ts +++ b/src/main.ts @@ -115,21 +115,25 @@ export async function run(): Promise { } const parentFieldName = `labels.${labelName}.${labelEvent}.${eventType}`; - const logURL = `${process.env['GITHUB_SERVER_URL']}/${process.env['GITHUB_REPOSITORY']}/actions/runs/${process.env['GITHUB_RUN_ID']}`; - const commentBody = - config.labels[labelIndex][`${labelEvent}`][`${eventType}`].body + - `\n\n
` + + + // Merge comment body + const commentMain = config.labels[labelIndex][`${labelEvent}`][`${eventType}`].body + '\n\n'; + const commentHeader = config.comment.header + '\n\n'; + const commentFooter = config.comment.footer + '\n\n'; + const commentFooterLinks = + `
` + `Log` + ` | ` + `Bot Usage` + `
\n` + '\n\n'; + const rawCommentBody = commentHeader + commentMain + commentFooter + commentFooterLinks; - if (commentBody === '' || commentBody === void 0) { + if (commentMain === '' || commentMain === void 0) { core.info(`[INFO] no configuration ${parentFieldName}.body`); } else { - groupConsoleLog('commentBody', commentBody, core.isDebug()); + groupConsoleLog('rawCommentBody', rawCommentBody, core.isDebug()); } const finalAction = config.labels[labelIndex][`${labelEvent}`][`${eventType}`].action; @@ -163,7 +167,7 @@ export async function run(): Promise { return {}; } })(); - const commentBodyRendered = Mustache.render(commentBody, commentBodyView); + const commentBodyRendered = Mustache.render(rawCommentBody, commentBodyView); groupConsoleLog('commentBodyRendered', commentBodyRendered, core.isDebug()); // Create octokit client