From a9d6e852244b376dbade8e9c5b79188a22c3abcf Mon Sep 17 00:00:00 2001 From: ykpythemind Date: Wed, 29 Dec 2021 17:33:41 +0900 Subject: [PATCH] reaction --- README.md | 5 +++-- dist/index.js | 33 ++++++++++++++++++++------------- index.js | 33 ++++++++++++++++++++------------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 8d5278d..5b41707 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ on: types: [created] jobs: - prettier_job: + prettier: runs-on: ubuntu-latest - name: prettier job + name: Run Prettier steps: - name: Checkout uses: actions/checkout@v2 @@ -21,6 +21,7 @@ jobs: - uses: actions/setup-node@v2 with: node-version: "14" + cache: 'npm' - run: npm ci diff --git a/dist/index.js b/dist/index.js index e2ce90f..a6cd0b6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -51930,7 +51930,6 @@ const { spawnSync } = __nccwpck_require__(2081); (async () => { try { - console.log("hey! from branch t2"); const prettierCommand = core.getInput("prettier_command"); const pullRequestNumber = github.context.payload.issue.number; @@ -51944,16 +51943,24 @@ const { spawnSync } = __nccwpck_require__(2081); return; } - // TODO: reaction here - const octokit = new Octokit(); + + const owner = github.context.repo.owner; + const repo = github.context.repo.repo; + + octokit.reactions.createForIssueComment({ + owner, + repo, + comment_id: github.context.payload.comment.id, + content: "+1", + }); + const { data } = await octokit.pulls.get({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, }); - // const baseBranch = data.base.ref const branch = data.head.ref; await exec.exec(`git fetch origin ${branch} --depth 1`); @@ -51961,8 +51968,8 @@ const { spawnSync } = __nccwpck_require__(2081); // todo: paginate const { data: fileList } = await octokit.pulls.listFiles({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, }); @@ -51987,7 +51994,7 @@ const { spawnSync } = __nccwpck_require__(2081); // } if (error) { - console.log(error); + console.error(error); } const cmdOutput = stdout.toString(); @@ -51997,8 +52004,8 @@ const { spawnSync } = __nccwpck_require__(2081); const body = `prettier executed. (exit with status ${status})\n\n${cmdOutput}`; await octokit.pulls.createReview({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, body: body, event: "COMMENT", @@ -52011,8 +52018,8 @@ const { spawnSync } = __nccwpck_require__(2081); if (error) { const body = `error: ${error}`; await octokit.pulls.createReview({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, body: body, event: "COMMENT", diff --git a/index.js b/index.js index 1b45263..a3817bf 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,6 @@ const { spawnSync } = require("child_process"); (async () => { try { - console.log("hey! from branch t2"); const prettierCommand = core.getInput("prettier_command"); const pullRequestNumber = github.context.payload.issue.number; @@ -21,16 +20,24 @@ const { spawnSync } = require("child_process"); return; } - // TODO: reaction here - const octokit = new Octokit(); + + const owner = github.context.repo.owner; + const repo = github.context.repo.repo; + + octokit.reactions.createForIssueComment({ + owner, + repo, + comment_id: github.context.payload.comment.id, + content: "+1", + }); + const { data } = await octokit.pulls.get({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, }); - // const baseBranch = data.base.ref const branch = data.head.ref; await exec.exec(`git fetch origin ${branch} --depth 1`); @@ -38,8 +45,8 @@ const { spawnSync } = require("child_process"); // todo: paginate const { data: fileList } = await octokit.pulls.listFiles({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, }); @@ -64,7 +71,7 @@ const { spawnSync } = require("child_process"); // } if (error) { - console.log(error); + console.error(error); } const cmdOutput = stdout.toString(); @@ -74,8 +81,8 @@ const { spawnSync } = require("child_process"); const body = `prettier executed. (exit with status ${status})\n\n${cmdOutput}`; await octokit.pulls.createReview({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, body: body, event: "COMMENT", @@ -88,8 +95,8 @@ const { spawnSync } = require("child_process"); if (error) { const body = `error: ${error}`; await octokit.pulls.createReview({ - owner: github.context.repo.owner, - repo: github.context.repo.repo, + owner, + repo, pull_number: pullRequestNumber, body: body, event: "COMMENT",