Skip to content

Commit

Permalink
feat: Support comment header and footer
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Nov 25, 2020
1 parent bd43808 commit 43311f0
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,21 +115,25 @@ export async function run(): Promise<void> {
}

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 +

// Merge comment body
const commentMain = config.labels[labelIndex][`${labelEvent}`][`${eventType}`].body;
const commentHeader = config.comment.header;
const commentFooter = config.comment.footer;
const commentFooterLinks =
`\n\n<div align="right">` +
`<a href="${logURL}">Log</a>` +
` | ` +
`<a href="https://github.com/peaceiris/actions-label-commenter#readme">Bot Usage</a>` +
`</div>\n` +
'\n<!-- peaceiris/actions-label-commenter -->\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;
Expand Down Expand Up @@ -163,7 +167,7 @@ export async function run(): Promise<void> {
return {};
}
})();
const commentBodyRendered = Mustache.render(commentBody, commentBodyView);
const commentBodyRendered = Mustache.render(rawCommentBody, commentBodyView);
groupConsoleLog('commentBodyRendered', commentBodyRendered, core.isDebug());

// Create octokit client
Expand Down

0 comments on commit 43311f0

Please sign in to comment.