From 8084bec170bfd7133b1aaf9f3783b08b584f68a3 Mon Sep 17 00:00:00 2001 From: Mohammad Bagher Abiyat Date: Thu, 21 Mar 2024 08:20:09 +0330 Subject: [PATCH] ohash --- package.json | 1 + packages/backend/server/routes/webhook.post.ts | 9 ++++----- packages/cli/index.ts | 4 ++++ pnpm-lock.yaml | 3 +++ 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 96b9ad98..cd7d7bba 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "devDependencies": { "eslint": "^8.57.0", "eslint-config-unjs": "^0.2.1", + "ohash": "^1.1.3", "prettier": "^3.2.5", "typescript": "^5.4.2" }, diff --git a/packages/backend/server/routes/webhook.post.ts b/packages/backend/server/routes/webhook.post.ts index 99223276..1c95e099 100644 --- a/packages/backend/server/routes/webhook.post.ts +++ b/packages/backend/server/routes/webhook.post.ts @@ -9,17 +9,16 @@ export default eventHandler(async (event) => { secret: webhookSecret, }, }); - app.webhooks.on("workflow_job", ({ octokit, payload }) => { - console.log(payload) + app.webhooks.on("workflow_job.queued", ({ octokit, payload }) => { + console.log(payload.workflow_job.node_id) }); - // event.context.cloudflare.request. type EmitterWebhookEvent = Parameters[0] const id: EmitterWebhookEvent['id'] = event.headers.get("x-github-delivery"); const name = event.headers.get("x-github-event") as EmitterWebhookEvent['name']; const signature = event.headers.get("x-hub-signature-256") ?? ""; - const payloadString = await event.context.cloudflare.request.text(); - const payload: EmitterWebhookEvent['payload'] = JSON.parse(payloadString); + const payloadString = await readRawBody(event); + const payload = await readBody(event); // Verify webhook signature try { diff --git a/packages/cli/index.ts b/packages/cli/index.ts index 18b57e40..79ecd977 100644 --- a/packages/cli/index.ts +++ b/packages/cli/index.ts @@ -1,6 +1,7 @@ import { defineCommand, runMain } from "citty"; // import { createRequire } from "module"; import { version } from "./package.json"; +import {hash} from 'ohash' import { Octokit } from "@octokit/action"; import "./environments"; @@ -14,6 +15,9 @@ const eventPayload = await import(process.env.GITHUB_EVENT_PATH, { with: { type: "json" }, }); +console.log(eventPayload) +console.log(hash(eventPayload)) + // console.log(octokit) // console.log(eventPayload) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2647ad1f..30e3d0ac 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ importers: eslint-config-unjs: specifier: ^0.2.1 version: 0.2.1(eslint@8.57.0)(typescript@5.4.2) + ohash: + specifier: ^1.1.3 + version: 1.1.3 prettier: specifier: ^3.2.5 version: 3.2.5