diff --git a/.github/label-commenter-config.yml b/.github/label-commenter-config.yml index 345ad642..1a4304ae 100644 --- a/.github/label-commenter-config.yml +++ b/.github/label-commenter-config.yml @@ -36,3 +36,9 @@ labels: labeled: issue: body: This issue is easy for contributing. Everyone can work on this. + - name: proposal + labeled: + issue: + body: | + Thank you @{{ sender.login }} for suggesting this. + The maintainer will reply. diff --git a/.prettierrc.json b/.prettierrc.json index 97b6e6db..05b31a87 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,11 +1,11 @@ { - "printWidth": 80, - "tabWidth": 2, - "useTabs": false, - "semi": true, - "singleQuote": true, - "trailingComma": "none", - "bracketSpacing": false, - "arrowParens": "avoid", - "parser": "typescript" - } + "printWidth": 100, + "tabWidth": 2, + "useTabs": false, + "semi": true, + "singleQuote": true, + "trailingComma": "none", + "bracketSpacing": false, + "arrowParens": "avoid", + "parser": "typescript" +} diff --git a/package-lock.json b/package-lock.json index 8a9bae6a..11a15bf0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1057,6 +1057,12 @@ "integrity": "sha1-aaI6OtKcrwCX8G7aWbNh7i8GOfY=", "dev": true }, + "@types/mustache": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@types/mustache/-/mustache-4.0.1.tgz", + "integrity": "sha512-wH6Tu9mbiOt0n5EvdoWy0VGQaJMHfLIxY/6wS0xLC7CV1taM6gESEzcYy0ZlWvxxiiljYvfDIvz4hHbUUDRlhw==", + "dev": true + }, "@types/node": { "version": "12.12.47", "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.47.tgz", @@ -7323,6 +7329,11 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "mustache": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.0.1.tgz", + "integrity": "sha512-yL5VE97+OXn4+Er3THSmTdCFCtx5hHWzrolvH+JObZnUYwuaG7XV+Ch4fR2cIrcYI0tFHxS7iyFYl14bW8y2sA==" + }, "nanomatch": { "version": "1.2.13", "resolved": "https://registry.npmjs.org/nanomatch/-/nanomatch-1.2.13.tgz", diff --git a/package.json b/package.json index 8162b2e3..9e209927 100644 --- a/package.json +++ b/package.json @@ -51,11 +51,13 @@ "dependencies": { "@actions/core": "^1.2.4", "@actions/github": "^3.0.0", - "js-yaml": "^3.14.0" + "js-yaml": "^3.14.0", + "mustache": "^4.0.1" }, "devDependencies": { "@types/jest": "^26.0.0", "@types/js-yaml": "^3.12.4", + "@types/mustache": "^4.0.1", "@types/node": "~12", "@typescript-eslint/eslint-plugin": "^3.3.0", "@typescript-eslint/parser": "^3.3.0", diff --git a/src/main.ts b/src/main.ts index c24d633c..12b83723 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,6 +5,7 @@ import {Inputs} from './interfaces'; import {getInputs} from './get-inputs'; import fs from 'fs'; import yaml from 'js-yaml'; +import Mustache from 'mustache'; async function closeIssue( githubClient: InstanceType, @@ -91,52 +92,50 @@ export async function run(): Promise { config.labels[labelIndex][`${labelEvent}`].issue === void 0 && config.labels[labelIndex][`${labelEvent}`].pr === void 0 ) { - throw new Error( - `not found any definition labels.${labelName}.${labelEvent}` - ); + throw new Error(`not found any definition labels.${labelName}.${labelEvent}`); } let eventType = ''; if (eventName === 'issues') { eventType = 'issue'; if (config.labels[labelIndex][`${labelEvent}`].issue === void 0) { - core.info( - `[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}` - ); + core.info(`[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}`); return; } } else if (eventName === 'pull_request') { eventType = 'pr'; if (config.labels[labelIndex][`${labelEvent}`].pr === void 0) { - core.info( - `[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}` - ); + core.info(`[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}`); return; } } - const commentBody = - config.labels[labelIndex][`${labelEvent}`][`${eventType}`].body; - const finalAction = - config.labels[labelIndex][`${labelEvent}`][`${eventType}`].action; + const commentBody = config.labels[labelIndex][`${labelEvent}`][`${eventType}`].body; + const finalAction = config.labels[labelIndex][`${labelEvent}`][`${eventType}`].action; core.info(`\ [INFO] commentBody: ${commentBody} [INFO] finalAction: ${finalAction}\ `); if (commentBody === '' || commentBody === void 0) { - core.info( - `[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}.body` - ); + core.info(`[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}.body`); } + // Render template + const commentBodyView = { + sender: { + login: (context.payload as any).sender.login // eslint-disable-line @typescript-eslint/no-explicit-any + } + }; + const commentBodyRendered = Mustache.render(commentBody, commentBodyView); + const githubToken = inps.GithubToken; const githubClient = getOctokit(githubToken); await githubClient.issues.createComment({ issue_number: context.issue.number, owner: context.repo.owner, repo: context.repo.repo, - body: commentBody + body: commentBodyRendered }); if (finalAction === 'close') { @@ -144,9 +143,7 @@ export async function run(): Promise { } else if (finalAction === 'open') { await openIssue(githubClient, issueNumber); } else if (finalAction === '' || finalAction === void 0) { - core.info( - `[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}.action` - ); + core.info(`[INFO] no configuration labels.${labelName}.${labelEvent}.${eventType}.action`); return; } else { throw new Error(