@@ -271,7 +271,7 @@ private function get(array $urls, bool $isRecipe = false, int $try = 3): array
271
271
$ options = [];
272
272
273
273
foreach ($ urls as $ url ) {
274
- $ cacheKey = preg_replace ( ' {[^a-z0-9.]}i ' , ' - ' , $ url );
274
+ $ cacheKey = self :: generateCacheKey ( $ url );
275
275
$ headers = [];
276
276
277
277
if (preg_match ('{^https?://api\.github\.com/} ' , $ url )) {
@@ -300,7 +300,7 @@ private function get(array $urls, bool $isRecipe = false, int $try = 3): array
300
300
foreach ($ urls as $ url ) {
301
301
$ jobs [] = $ this ->rfs ->add ($ url , $ options [$ url ])->then (function (ComposerResponse $ response ) use ($ url , &$ responses ) {
302
302
if (200 === $ response ->getStatusCode ()) {
303
- $ cacheKey = preg_replace ( ' {[^a-z0-9.]}i ' , ' - ' , $ url );
303
+ $ cacheKey = self :: generateCacheKey ( $ url );
304
304
$ responses [$ url ] = $ this ->parseJson ($ response ->getBody (), $ url , $ cacheKey , $ response ->getHeaders ())->getBody ();
305
305
}
306
306
}, function (\Exception $ e ) use ($ url , &$ retries ) {
@@ -314,7 +314,7 @@ private function get(array $urls, bool $isRecipe = false, int $try = 3): array
314
314
}
315
315
$ this ->rfs ->download ($ urls , function ($ url ) use ($ options , &$ responses , &$ retries , &$ error ) {
316
316
try {
317
- $ cacheKey = preg_replace ( ' {[^a-z0-9.]}i ' , ' - ' , $ url );
317
+ $ cacheKey = self :: generateCacheKey ( $ url );
318
318
$ origin = method_exists ($ this ->rfs , 'getOrigin ' ) ? $ this ->rfs ::getOrigin ($ url ) : parse_url ($ url , \PHP_URL_HOST );
319
319
$ json = $ this ->rfs ->getContents ($ origin , $ url , false , $ options [$ url ]);
320
320
if (200 === $ this ->rfs ->findStatusCode ($ this ->rfs ->getLastHeaders ())) {
@@ -412,4 +412,11 @@ private function initialize()
412
412
$ this ->endpoints [$ endpoint ] = $ config ;
413
413
}
414
414
}
415
+
416
+ private static function generateCacheKey (string $ url ): string
417
+ {
418
+ $ url = preg_replace ('{^https://api.github.com/repos/([^/]++/[^/]++)/contents/} ' , '$1/ ' , $ url );
419
+
420
+ return preg_replace ('{[^a-z0-9.]}i ' , '- ' , $ url );
421
+ }
415
422
}
0 commit comments