diff --git a/src/index.ts b/src/index.ts index 7703ed9..67e8b7a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import express from "express"; import crypto from "crypto"; import { z } from "zod"; import { env } from "./env"; +import { syncGiteaRewrites } from "./sync"; const webhookSchema = z.object({ action: z.enum(["deleted", "created"]), @@ -45,7 +46,11 @@ app.post("/", async (req, res) => { } const { action } = result.data; - console.log(`Webhook received: ${action}`); + console.log(`Received event: ${action}`); + + console.log("Synchronizing..."); + const repos = await syncGiteaRewrites(); + console.log(`Done (${repos.length}): ${repos.join(", ")}`); res.sendStatus(200); }); @@ -53,3 +58,5 @@ app.post("/", async (req, res) => { app.listen(env.PORT, () => { console.log(`Server running on port ${env.PORT}`); }); + +await syncGiteaRewrites(); diff --git a/src/sync.ts b/src/sync.ts index 37f5b62..1107b73 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -62,7 +62,8 @@ const createOutputFile = async (repos: string[]): Promise => { } }; -export const syncGiteaRewrites = async (): Promise => { +export const syncGiteaRewrites = async (): Promise => { const repos = await fetchGiteaRepos(); await createOutputFile(repos); + return repos; };