feat: periodical synchronization to handle repo renaming
All checks were successful
Deploy / build (push) Successful in 25s
Deploy / deploy (push) Successful in 1s

This commit is contained in:
2026-09-25 20:34:31 +02:00
parent 915a466310
commit fd8f06b1ee
4 changed files with 21 additions and 0 deletions

View File

@@ -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"

View File

@@ -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`.

View File

@@ -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);

View File

@@ -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,
);
}