feat: periodical synchronization to handle repo renaming
This commit is contained in:
@@ -13,3 +13,5 @@ GITEA_WEBHOOK_SECRET=""
|
|||||||
# File used by traefik to create the middleware
|
# File used by traefik to create the middleware
|
||||||
TEMPLATE_FILE="gitea-rewrites.yml.in"
|
TEMPLATE_FILE="gitea-rewrites.yml.in"
|
||||||
OUTPUT_FILE="gitea-rewrites.yml"
|
OUTPUT_FILE="gitea-rewrites.yml"
|
||||||
|
# Periodic resync, needed because Gitea sends no webhook on repo rename (0 to disable)
|
||||||
|
SYNC_INTERVAL_MINUTES="5"
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ services:
|
|||||||
- GITEA_WEBHOOK_SECRET
|
- GITEA_WEBHOOK_SECRET
|
||||||
- TEMPLATE_FILE=/config/gitea-rewrites.yml.in
|
- TEMPLATE_FILE=/config/gitea-rewrites.yml.in
|
||||||
- OUTPUT_FILE=/config/gitea-rewrites.yml
|
- OUTPUT_FILE=/config/gitea-rewrites.yml
|
||||||
|
- SYNC_INTERVAL_MINUTES=5 # optional, default = 5, 0 to disable
|
||||||
volumes:
|
volumes:
|
||||||
- /etc/traefik/dynamic:/config
|
- /etc/traefik/dynamic:/config
|
||||||
networks:
|
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.
|
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.
|
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
|
## 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`.
|
You can put anything in here, `{{REPOSITORIES}}` will be pipe-separated repos list (`repo-a|repo-b`) and `{{USERNAME}}` just contain `GITEA_USERNAME`.
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ const schema = z.object({
|
|||||||
GITEA_WEBHOOK_SECRET: z.string(),
|
GITEA_WEBHOOK_SECRET: z.string(),
|
||||||
TEMPLATE_FILE: z.string(),
|
TEMPLATE_FILE: z.string(),
|
||||||
OUTPUT_FILE: z.string(),
|
OUTPUT_FILE: z.string(),
|
||||||
|
SYNC_INTERVAL_MINUTES: z.coerce.number().min(0).default(5),
|
||||||
});
|
});
|
||||||
|
|
||||||
const result = schema.safeParse(process.env);
|
const result = schema.safeParse(process.env);
|
||||||
|
|||||||
13
src/index.ts
13
src/index.ts
@@ -60,3 +60,16 @@ app.listen(env.PORT, () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
await syncGiteaRewrites();
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user