@@ -103,18 +103,20 @@ function isGitHubUrl(url: string): boolean {
103103}
104104
105105/**
106- * Adds GitHub authentication headers to a headers object if a token is available
107- * and the URL is a GitHub URL.
106+ * Returns GitHub authentication headers if a token is available and the URL is a GitHub URL.
108107 */
109- function addGitHubAuthHeaders ( headers : HeadersInit , url : string ) : void {
108+ function getGitHubAuthHeaders ( url : string ) : Record < string , string > {
110109 if ( gitHubAuthToken && isGitHubUrl ( url ) ) {
111110 // GitHub Git protocol requires Basic Auth with token as username and empty password
112111 const basicAuth = btoa ( `${ gitHubAuthToken } :` ) ;
113- headers [ 'Authorization' ] = `Basic ${ basicAuth } ` ;
114- // Tell CORS proxy to forward the Authorization header
115- // Must be lowercase because the CORS proxy lowercases header names for comparison
116- headers [ 'X-Cors-Proxy-Allowed-Request-Headers' ] = 'authorization' ;
112+ return {
113+ Authorization : `Basic ${ basicAuth } ` ,
114+ // Tell CORS proxy to forward the Authorization header
115+ // Must be lowercase because the CORS proxy lowercases header names for comparison
116+ 'X-Cors-Proxy-Allowed-Request-Headers' : 'authorization' ,
117+ } ;
117118 }
119+ return { } ;
118120}
119121
120122/**
@@ -340,18 +342,15 @@ export async function listGitRefs(
340342 ] ) ) as any
341343 ) ;
342344
343- const headers : HeadersInit = {
344- Accept : 'application/x-git-upload-pack-advertisement' ,
345- 'content-type' : 'application/x-git-upload-pack-request' ,
346- 'Content-Length' : `${ packbuffer . length } ` ,
347- 'Git-Protocol' : 'version=2' ,
348- } ;
349-
350- addGitHubAuthHeaders ( headers , repoUrl ) ;
351-
352345 const response = await fetch ( repoUrl + '/git-upload-pack' , {
353346 method : 'POST' ,
354- headers,
347+ headers : {
348+ Accept : 'application/x-git-upload-pack-advertisement' ,
349+ 'content-type' : 'application/x-git-upload-pack-request' ,
350+ 'Content-Length' : `${ packbuffer . length } ` ,
351+ 'Git-Protocol' : 'version=2' ,
352+ ...getGitHubAuthHeaders ( repoUrl ) ,
353+ } ,
355354 body : packbuffer as any ,
356355 } ) ;
357356
@@ -506,17 +505,14 @@ async function fetchWithoutBlobs(repoUrl: string, commitHash: string) {
506505 ] ) ) as any
507506 ) ;
508507
509- const headers : HeadersInit = {
510- Accept : 'application/x-git-upload-pack-advertisement' ,
511- 'content-type' : 'application/x-git-upload-pack-request' ,
512- 'Content-Length' : `${ packbuffer . length } ` ,
513- } ;
514-
515- addGitHubAuthHeaders ( headers , repoUrl ) ;
516-
517508 const response = await fetch ( repoUrl + '/git-upload-pack' , {
518509 method : 'POST' ,
519- headers,
510+ headers : {
511+ Accept : 'application/x-git-upload-pack-advertisement' ,
512+ 'content-type' : 'application/x-git-upload-pack-request' ,
513+ 'Content-Length' : `${ packbuffer . length } ` ,
514+ ...getGitHubAuthHeaders ( repoUrl ) ,
515+ } ,
520516 body : packbuffer as any ,
521517 } ) ;
522518
@@ -671,17 +667,14 @@ async function fetchObjects(url: string, objectHashes: string[]) {
671667 ] ) ) as any
672668 ) ;
673669
674- const headers : HeadersInit = {
675- Accept : 'application/x-git-upload-pack-advertisement' ,
676- 'content-type' : 'application/x-git-upload-pack-request' ,
677- 'Content-Length' : `${ packbuffer . length } ` ,
678- } ;
679-
680- addGitHubAuthHeaders ( headers , url ) ;
681-
682670 const response = await fetch ( url + '/git-upload-pack' , {
683671 method : 'POST' ,
684- headers,
672+ headers : {
673+ Accept : 'application/x-git-upload-pack-advertisement' ,
674+ 'content-type' : 'application/x-git-upload-pack-request' ,
675+ 'Content-Length' : `${ packbuffer . length } ` ,
676+ ...getGitHubAuthHeaders ( url ) ,
677+ } ,
685678 body : packbuffer as any ,
686679 } ) ;
687680
0 commit comments