feat: add gitea/forgejo support

This commit is contained in:
RhenCloud 2026-08-11 22:01:04 +08:00
parent ace036c209
commit aec0d1a257
43 changed files with 683 additions and 130 deletions

22
src/providers/index.ts Normal file
View file

@ -0,0 +1,22 @@
import type { Provider } from "./types";
import { githubProvider } from "./github";
import { giteaProvider } from "./gitea";
export type { Provider } from "./types";
export { verifySignature } from "./github/verify";
/**
* Detection order matters: Gitea webhooks also send GitHub-compatible headers
* (`X-GitHub-Event`, `X-Hub-Signature-256`, ...), so a Gitea request would
* match the GitHub provider too. Check Gitea first real GitHub requests
* never send `X-Gitea-Event`.
*/
const providers: Provider[] = [giteaProvider, githubProvider];
/**
* Pick the webhook provider for a request based on its headers (e.g.
* `X-GitHub-Event` / `X-Gitea-Event`). Returns null when no provider matches.
*/
export function detectProvider(headers: Record<string, string>): Provider | null {
return providers.find((p) => p.matches(headers)) ?? null;
}