Skip to content

Commit

Permalink
Merge pull request #6 from Doarakko/topic/power-up
Browse files Browse the repository at this point in the history
Topic/power up
  • Loading branch information
Doarakko authored Aug 23, 2022
2 parents 9d5155e + 7a6ccdf commit 81066d4
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 76 deletions.
35 changes: 17 additions & 18 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
{
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {
}
}
"env": {
"commonjs": true,
"es6": true,
"jest": true,
"node": true
},
"extends": "eslint:recommended",
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module"
},
"rules": {}
}
10 changes: 10 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "avoid"
}
48 changes: 24 additions & 24 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,65 @@
import fetch from "node-fetch";
import { getInput, setFailed } from "@actions/core";
import { context } from "@actions/github";
import { Octokit } from "@octokit/core";
import * as core from "@actions/core";
import fetch from 'node-fetch';
import { getInput, setFailed } from '@actions/core';
import { context } from '@actions/github';
import { Octokit } from '@octokit/core';
import * as core from '@actions/core';

async function run() {
try {
const githubToken = getInput("github-token");
const githubToken = getInput('github-token');
const octokit = new Octokit({ auth: githubToken });

if (!(context.payload.comment.body || '').toLowerCase().match(/lgtm/)) {
core.debug('nothing to do.');
return;
}

switch (context.eventName) {
case "issue_comment":
if(!(context.payload.comment.body || '').match(/lgtm/)){
core.debug("nothing to do.");
return;
}
case 'issue_comment':
break;
case "pull_request_review":
if(!(context.payload.review.body || '').match(/lgtm/) && context.payload.review.state !== "approved"){
core.debug("nothing to do.");
case 'pull_request_review':
if (context.payload.review.state !== 'approved') {
core.debug('nothing to do.');
return;
}
break;
case "pull_request_review_comment":
if(!(context.payload.comment.body || '').match(/lgtm/)){
core.debug("nothing to do.");
return;
}
case 'pull_request_review_comment':
break;
default:
core.debug("nothing to do.");
core.debug('nothing to do.');
return;
}

fetch("https://lgtmoon.herokuapp.com/api/images/random")
.then((response) => {
fetch('https://lgtmoon.herokuapp.com/api/images/random')
.then(response => {
return response.json();
})
.then((data) => {
.then(data => {
const imageUrl = data.images[0].url;

if (context.eventName === "issue_comment" || context.eventName === "pull_request_review") {
if (
context.eventName === 'issue_comment' ||
context.eventName === 'pull_request_review'
) {
octokit.request(
"POST /repos/{owner}/{repo}/issues/{issue_number}/comments",
'POST /repos/{owner}/{repo}/issues/{issue_number}/comments',
{
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `![](${imageUrl})`,
}
},
);
} else if (context.eventName === "pull_request_review_comment") {
} else if (context.eventName === 'pull_request_review_comment') {
octokit.request(
"POST /repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies",
'POST /repos/{owner}/{repo}/pulls/{pull_number}/comments/{comment_id}/replies',
{
owner: context.repo.owner,
repo: context.repo.repo,
body: `![](${imageUrl})`,
pull_number: context.payload.pull_request.number,
comment_id: context.payload.comment.id,
}
},
);
}
});
Expand Down
24 changes: 23 additions & 1 deletion package-lock.json

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

9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
"main": "index.js",
"scripts": {
"lint": "eslint .",
"prepare": "ncc build index.js -o dist --source-map --license licenses.txt"
"format": "prettier --write '**/*.js'",
"prepare": "ncc build index.js -o dist --source-map --license licenses.txt",
"all": "npm run lint && npm run format && npm run prepare"
},
"repository": {
"type": "git",
Expand All @@ -26,6 +28,7 @@
},
"devDependencies": {
"@vercel/ncc": "^0.27.0",
"eslint": "^7.20.0"
"eslint": "^7.20.0",
"prettier": "^2.7.1"
}
}
}

0 comments on commit 81066d4

Please sign in to comment.