Initial commit

This commit is contained in:
Ismo Vuorinen
2022-10-17 09:42:32 +03:00
commit 78cca41be4
27 changed files with 9319 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace App\Fetchers;
use Illuminate\Support\Facades\Http;
class GitHubRestApi {
public static function getBranches( string $vendor, string $package ) : array {
$pages = self::downloader( $vendor, $package );
$pages = \collect($pages)
->flatten(1)
->toArray();
return $pages;
}
public static function downloader( $vendor, $package ) : array {
$responses = [];
$continue = true;
$page = 1;
$gh_api = sprintf(
'https://api.github.com/repos/%s/%s/branches?per_page=100',
$vendor,
$package
);
while ( $continue ) {
$response = Http::get( $gh_api . '&page=' . $page );
if ( empty( $response ) ) {
$continue = false;
}
$responses[ $page ] = $response;
$page ++;
}
return $responses;
}
}