Skip to content

Commit

Permalink
feat: Support comment header and footer (#327)
Browse files Browse the repository at this point in the history
Pull Request for Issue #318
  • Loading branch information
peaceiris authored Nov 25, 2020
1 parent 39ed4e9 commit 1d49a01
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 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 +
`\n\n<div align="right">` +

// 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 =
`<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 1d49a01

Please sign in to comment.