From 852898b94e4a7d346e26bf8b1632f84d59a708f4 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj <1+selimaj-dev@noreply.localhost> Date: Mon, 28 Sep 2026 05:29:37 +0000 Subject: [PATCH] Update server.mjs --- server.mjs | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/server.mjs b/server.mjs index b44a373..9b7d463 100644 --- a/server.mjs +++ b/server.mjs @@ -1,5 +1,4 @@ import http from 'node:http'; -import crypto from 'node:crypto'; import { execFile } from 'node:child_process'; import { promisify } from 'node:util'; import fs from 'node:fs/promises'; @@ -7,7 +6,8 @@ import os from 'node:os'; import path from 'node:path'; const run = promisify(execFile); -const { GITEA_URL, GITEA_TOKEN, WEBHOOK_SECRET, OWNER_LOGIN = 'selimaj-dev', PORT = 3000 } = process.env; +const { GITEA_URL, GITEA_TOKEN } = process.env; +const OWNER = 'selimaj-dev'; const gitEnv = { ...process.env, @@ -17,7 +17,6 @@ const gitEnv = { }; const claudeEnv = { ...process.env }; delete claudeEnv.GITEA_TOKEN; -delete claudeEnv.WEBHOOK_SECRET; const api = async (method, p, body) => { const r = await fetch(`${GITEA_URL}/api/v1${p}`, { @@ -29,7 +28,6 @@ const api = async (method, p, body) => { return r.status === 204 ? null : r.json(); }; const git = (dir, ...args) => run('git', args, { cwd: dir, env: gitEnv }); - const busy = new Set(); async function handle(ev) { @@ -102,17 +100,14 @@ http.createServer((req, res) => { const chunks = []; req.on('data', (c) => chunks.push(c)); req.on('end', () => { - const raw = Buffer.concat(chunks); - const sig = req.headers['x-gitea-signature'] || ''; - const want = crypto.createHmac('sha256', WEBHOOK_SECRET).update(raw).digest('hex'); - const ok = sig.length === want.length && crypto.timingSafeEqual(Buffer.from(sig), Buffer.from(want)); - if (!ok) { res.writeHead(401).end(); return; } res.writeHead(200).end('ok'); - if (req.headers['x-gitea-event'] !== 'issue_comment') return; - const ev = JSON.parse(raw); - if (ev.action !== 'created') return; - if (ev.comment.user.login !== OWNER_LOGIN) return; - if (!ev.comment.body.includes('@claude')) return; - handle(ev); + try { + if (req.headers['x-gitea-event'] !== 'issue_comment') return; + const ev = JSON.parse(Buffer.concat(chunks)); + if (ev.action !== 'created') return; + if (ev.comment.user.login !== OWNER) return; + if (!ev.comment.body.includes('@claude')) return; + handle(ev); + } catch (e) { console.error(e.message); } }); -}).listen(PORT); \ No newline at end of file +}).listen(3000); \ No newline at end of file