mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-11-03 07:42:19 +01:00
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.
27 lines
1.0 KiB
TypeScript
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;
|
|
}
|