Skip to content

Commit

Permalink
Merge pull request #27 from ykpythemind/add_reaction
Browse files Browse the repository at this point in the history
reaction
  • Loading branch information
ykpythemind authored Dec 29, 2021
2 parents 0923b5c + a9d6e85 commit f78d4d7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,6 +21,7 @@ jobs:
- uses: actions/setup-node@v2
with:
node-version: "14"
cache: 'npm'

- run: npm ci

Expand Down
33 changes: 20 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51944,25 +51943,33 @@ 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`);
await exec.exec(`git switch ${branch}`);

// todo: paginate
const { data: fileList } = await octokit.pulls.listFiles({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
owner,
repo,
pull_number: pullRequestNumber,
});

Expand All @@ -51987,7 +51994,7 @@ const { spawnSync } = __nccwpck_require__(2081);
// }

if (error) {
console.log(error);
console.error(error);
}

const cmdOutput = stdout.toString();
Expand All @@ -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",
Expand All @@ -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",
Expand Down
33 changes: 20 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,25 +20,33 @@ 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`);
await exec.exec(`git switch ${branch}`);

// todo: paginate
const { data: fileList } = await octokit.pulls.listFiles({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
owner,
repo,
pull_number: pullRequestNumber,
});

Expand All @@ -64,7 +71,7 @@ const { spawnSync } = require("child_process");
// }

if (error) {
console.log(error);
console.error(error);
}

const cmdOutput = stdout.toString();
Expand All @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit f78d4d7

Please sign in to comment.