@@ -117,20 +117,22 @@ async function respectRateLimits(): Promise<void> {
117117 * @param options - Fetch options
118118 * @param env - Environment containing GitHub token if available
119119 * @param retryCount - Current retry attempt (used internally)
120+ * @param useAuth - Whether to include authorization header if token is available (default: true)
120121 * @returns The API response or null if failed
121122 */
122123export async function githubApiRequest (
123124 url : string ,
124125 options : RequestInit = { } ,
125126 env : any ,
126127 retryCount = 0 ,
128+ useAuth = true ,
127129) : Promise < Response | null > {
128130 try {
129131 // Extract repository context for metrics
130132 const repoContext = extractRepoContextFromUrl ( url ) ;
131133
132134 // Track GitHub query count using Cloudflare analytics
133- if ( env ? .CLOUDFLARE_ANALYTICS && retryCount === 0 ) {
135+ if ( env . CLOUDFLARE_ANALYTICS && retryCount === 0 ) {
134136 env . CLOUDFLARE_ANALYTICS . writeDataPoint ( {
135137 blobs : [ url , repoContext ] ,
136138 doubles : [ 1 ] ,
@@ -141,15 +143,15 @@ export async function githubApiRequest(
141143 // Wait for rate limit if necessary
142144 await respectRateLimits ( ) ;
143145
144- // Add GitHub authentication if token is available
146+ // Add GitHub authentication if token is available and useAuth is true
145147 const headers = new Headers ( options . headers || { } ) ;
146148 headers . set ( "Accept" , "application/vnd.github.v3+json" ) ;
147149 headers . set (
148150 "User-Agent" ,
149151 "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36" ,
150152 ) ;
151153
152- if ( env ? .GITHUB_TOKEN ) {
154+ if ( useAuth && env . GITHUB_TOKEN ) {
153155 headers . set ( "Authorization" , `token ${ env . GITHUB_TOKEN } ` ) ;
154156 }
155157
@@ -286,19 +288,21 @@ export async function searchFileByName(
286288 * @param branch - Branch name
287289 * @param path - File path
288290 * @param env - Environment for GitHub token
291+ * @param useAuth - Whether to use authentication
289292 */
290293export async function fetchRawFile (
291294 owner : string ,
292295 repo : string ,
293296 branch : string ,
294297 path : string ,
295298 env : any ,
299+ useAuth = false ,
296300) : Promise < string | null > {
297301 const url = `https://raw.githubusercontent.com/${ owner } /${ repo } /${ branch } /${ path } ` ;
298302
299303 // Raw GitHub content doesn't need the GitHub API token
300304 // But we still use the client for rate limiting
301- const response = await githubApiRequest ( url , { } , env ) ;
305+ const response = await githubApiRequest ( url , { } , env , 0 , useAuth ) ;
302306
303307 if ( ! response || ! response . ok ) {
304308 return null ;
0 commit comments