From fd8f06b1ee03351551c5dcbc5055eb13654599cd Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Fri, 25 Sep 2026 20:34:31 +0200 Subject: [PATCH] feat: periodical synchronization to handle repo renaming --- .env.example | 2 ++ README.md | 5 +++++ src/env.ts | 1 + src/index.ts | 13 +++++++++++++ 4 files changed, 21 insertions(+) diff --git a/.env.example b/.env.example index 8c544d1..104708b 100644 --- a/.env.example +++ b/.env.example @@ -13,3 +13,5 @@ GITEA_WEBHOOK_SECRET="" # File used by traefik to create the middleware TEMPLATE_FILE="gitea-rewrites.yml.in" OUTPUT_FILE="gitea-rewrites.yml" +# Periodic resync, needed because Gitea sends no webhook on repo rename (0 to disable) +SYNC_INTERVAL_MINUTES="5" diff --git a/README.md b/README.md index 279a784..63569e1 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,7 @@ services: - GITEA_WEBHOOK_SECRET - TEMPLATE_FILE=/config/gitea-rewrites.yml.in - OUTPUT_FILE=/config/gitea-rewrites.yml + - SYNC_INTERVAL_MINUTES=5 # optional, default = 5, 0 to disable volumes: - /etc/traefik/dynamic:/config networks: @@ -84,6 +85,10 @@ Lastly, for the triggers select "Custom Events", then "Repository". And you're done, just hit "Add Webhook" and the service will start working. The Gitea webhooks interface shows you the logs, so you can see here if it reached the service. +### Renamed repositories + +Gitea has no webhook event for repository renames (the "Repository" event only covers creation and deletion, and none of the other events fire on rename). To catch them, we also resyncs every `SYNC_INTERVAL_MINUTES` minutes (default 5). + ## Template Format You can put anything in here, `{{REPOSITORIES}}` will be pipe-separated repos list (`repo-a|repo-b`) and `{{USERNAME}}` just contain `GITEA_USERNAME`. diff --git a/src/env.ts b/src/env.ts index 5b4c511..a7d1c0e 100644 --- a/src/env.ts +++ b/src/env.ts @@ -9,6 +9,7 @@ const schema = z.object({ GITEA_WEBHOOK_SECRET: z.string(), TEMPLATE_FILE: z.string(), OUTPUT_FILE: z.string(), + SYNC_INTERVAL_MINUTES: z.coerce.number().min(0).default(5), }); const result = schema.safeParse(process.env); diff --git a/src/index.ts b/src/index.ts index 67e8b7a..b05d943 100644 --- a/src/index.ts +++ b/src/index.ts @@ -60,3 +60,16 @@ app.listen(env.PORT, () => { }); await syncGiteaRewrites(); + +if (env.SYNC_INTERVAL_MINUTES > 0) { + setInterval( + async () => { + try { + await syncGiteaRewrites(); + } catch (error) { + console.error("Periodic sync failed:", error); + } + }, + env.SYNC_INTERVAL_MINUTES * 60_000, + ); +}