@@ -117,20 +117,22 @@ async function respectRateLimits(): Promise<void> {
117
117
* @param options - Fetch options
118
118
* @param env - Environment containing GitHub token if available
119
119
* @param retryCount - Current retry attempt (used internally)
120
+ * @param useAuth - Whether to include authorization header if token is available (default: true)
120
121
* @returns The API response or null if failed
121
122
*/
122
123
export async function githubApiRequest (
123
124
url : string ,
124
125
options : RequestInit = { } ,
125
126
env : any ,
126
127
retryCount = 0 ,
128
+ useAuth = true ,
127
129
) : Promise < Response | null > {
128
130
try {
129
131
// Extract repository context for metrics
130
132
const repoContext = extractRepoContextFromUrl ( url ) ;
131
133
132
134
// Track GitHub query count using Cloudflare analytics
133
- if ( env ? .CLOUDFLARE_ANALYTICS && retryCount === 0 ) {
135
+ if ( env . CLOUDFLARE_ANALYTICS && retryCount === 0 ) {
134
136
env . CLOUDFLARE_ANALYTICS . writeDataPoint ( {
135
137
blobs : [ url , repoContext ] ,
136
138
doubles : [ 1 ] ,
@@ -141,15 +143,15 @@ export async function githubApiRequest(
141
143
// Wait for rate limit if necessary
142
144
await respectRateLimits ( ) ;
143
145
144
- // Add GitHub authentication if token is available
146
+ // Add GitHub authentication if token is available and useAuth is true
145
147
const headers = new Headers ( options . headers || { } ) ;
146
148
headers . set ( "Accept" , "application/vnd.github.v3+json" ) ;
147
149
headers . set (
148
150
"User-Agent" ,
149
151
"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" ,
150
152
) ;
151
153
152
- if ( env ? .GITHUB_TOKEN ) {
154
+ if ( useAuth && env . GITHUB_TOKEN ) {
153
155
headers . set ( "Authorization" , `token ${ env . GITHUB_TOKEN } ` ) ;
154
156
}
155
157
@@ -286,19 +288,21 @@ export async function searchFileByName(
286
288
* @param branch - Branch name
287
289
* @param path - File path
288
290
* @param env - Environment for GitHub token
291
+ * @param useAuth - Whether to use authentication
289
292
*/
290
293
export async function fetchRawFile (
291
294
owner : string ,
292
295
repo : string ,
293
296
branch : string ,
294
297
path : string ,
295
298
env : any ,
299
+ useAuth = false ,
296
300
) : Promise < string | null > {
297
301
const url = `https://raw.githubusercontent.com/${ owner } /${ repo } /${ branch } /${ path } ` ;
298
302
299
303
// Raw GitHub content doesn't need the GitHub API token
300
304
// 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 ) ;
302
306
303
307
if ( ! response || ! response . ok ) {
304
308
return null ;
0 commit comments