This commit is contained in:
Andras Bacsai
2023-05-30 15:52:17 +02:00
parent 6e72889294
commit 0f50d1accd
36 changed files with 715 additions and 273 deletions

View File

@@ -1,6 +1,7 @@
<?php
use App\Models\GithubApp;
use App\Models\GitlabApp;
use Illuminate\Support\Facades\Http;
use Lcobucci\JWT\Encoding\ChainedFormatter;
use Lcobucci\JWT\Encoding\JoseEncoder;
@@ -45,3 +46,20 @@ function generate_github_jwt_token(GithubApp $source)
->toString();
return $issuedToken;
}
function get_from_git_api(GithubApp|GitlabApp $source, $endpoint)
{
if ($source->getMorphClass() == 'App\Models\GithubApp') {
if ($source->is_public) {
$response = Http::github($source->api_url)->get($endpoint);
}
}
$json = $response->json();
if ($response->status() !== 200) {
throw new \Exception("Failed to get data from {$source->name} with error: " . $json['message']);
}
return [
'rate_limit_remaining' => $response->header('X-RateLimit-Remaining'),
'data' => collect($json)
];
}