Skip to content

Commit

Permalink
feat: Add placeholder feature
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Jun 21, 2020
1 parent dd06426 commit f7c8789
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .github/label-commenter-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
20 changes: 10 additions & 10 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -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"
}
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 17 additions & 20 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof GitHub>,
Expand Down Expand Up @@ -91,62 +92,58 @@ export async function run(): Promise<void> {
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') {
await closeIssue(githubClient, issueNumber);
} 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(
Expand Down

0 comments on commit f7c8789

Please sign in to comment.