Files
gitea-mirror/src/lib/github-app-client.ts
T
Jeremy Williams e5b4f751b3 feat: GitHub App installation auth for GitHub sources (#457)
Adds GitHub App installation as an authentication option for GitHub sources, with installation token refresh for Gitea 1.27+ pull mirrors, credential redaction, and the account filters applied to installation listings.
2026-10-20 08:38:28 +05:30

27 lines
1.0 KiB
TypeScript

/**
* Octokit for a GitHub App installation source.
*
* The client is the throttled public one with an installation token added to
* every request. Tokens come from resolveGitHubAccessToken, which caches them
* until shortly before they expire, so long runs keep working past the hour.
*/
import type { Octokit } from "@octokit/rest";
import { createPublicGitHubClient } from "@/lib/github";
import { resolveGitHubAccessToken } from "@/lib/github-app-credentials";
export function createGitHubAppClient(
credential: string,
{ userId, apiBaseUrl }: { userId?: string; apiBaseUrl?: string } = {}
): Octokit {
const octokit = createPublicGitHubClient(apiBaseUrl, userId);
const tokenApiBaseUrl =
apiBaseUrl || process.env.GH_API_URL || process.env.GITHUB_API_URL || "https://api.github.com";
octokit.hook.before("request", async (options) => {
options.headers = {
...options.headers,
authorization: `token ${await resolveGitHubAccessToken(credential, tokenApiBaseUrl)}`,
};
});
return octokit;
}