/** * Make a GitHub API request with rate limit handling * @param url - API URL to fetch * @param options - Fetch options * @param env - Environment containing GitHub token if available * @param retryCount - Current retry attempt (used internally) * @param useAuth - Whether to include authorization header if token is available (default: true) * @returns The API response or null if failed */export async function githubApiRequest( url: string, options: RequestInit = {}, env: CloudflareEnvironment, retryCount = 1, useAuth = true,): Promise<Response | null> { try { // Extract repository context for metrics const repoContext = extractRepoContextFromUrl(url); // Track GitHub query count using Cloudflare analytics if (env?.CLOUDFLARE_ANALYTICS && retryCount === 0) { env.CLOUDFLARE_ANALYTICS.writeDataPoint({ blobs: [url, repoContext], doubles: [1], indexes: ["github_api_request"], }); } // Wait for rate limit if necessary await respectRateLimits(); ...
You can use this function to make a Github API request with rate limiting handled.
It has the following parameters
* @param url - API URL to fetch * @param options - Fetch options * @param env - Environment containing GitHub token if available * @param retryCount - Current retry attempt (used internally) * @param useAuth - Whether to include authorization header if token is available (default: true)