mirror of
https://github.com/tiennm99/coolify.git
synced 2026-04-17 17:21:04 +00:00
fix(api): infinite loop with github app with many repos (#8052)
Co-authored-by: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,7 @@ use App\Rules\ValidGitRepositoryUrl;
|
|||||||
use App\Services\DockerImageParser;
|
use App\Services\DockerImageParser;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use OpenApi\Attributes as OA;
|
use OpenApi\Attributes as OA;
|
||||||
use Spatie\Url\Url;
|
use Spatie\Url\Url;
|
||||||
@@ -1344,24 +1345,28 @@ class ApplicationsController extends Controller
|
|||||||
return response()->json(['message' => 'Failed to generate Github App token.'], 400);
|
return response()->json(['message' => 'Failed to generate Github App token.'], 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$repositories = collect();
|
|
||||||
$page = 1;
|
|
||||||
$repositories = loadRepositoryByPage($githubApp, $token, $page);
|
|
||||||
if ($repositories['total_count'] > 0) {
|
|
||||||
while (count($repositories['repositories']) < $repositories['total_count']) {
|
|
||||||
$page++;
|
|
||||||
$repositories = loadRepositoryByPage($githubApp, $token, $page);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$gitRepository = $request->git_repository;
|
$gitRepository = $request->git_repository;
|
||||||
if (str($gitRepository)->startsWith('http') || str($gitRepository)->contains('github.com')) {
|
if (str($gitRepository)->startsWith('http') || str($gitRepository)->contains('github.com')) {
|
||||||
$gitRepository = str($gitRepository)->replace('https://', '')->replace('http://', '')->replace('github.com/', '');
|
$gitRepository = str($gitRepository)->replace('https://', '')->replace('http://', '')->replace('github.com/', '');
|
||||||
}
|
}
|
||||||
$gitRepositoryFound = collect($repositories['repositories'])->firstWhere('full_name', $gitRepository);
|
$gitRepository = str($gitRepository)->trim('/')->replaceEnd('.git', '')->toString();
|
||||||
if (! $gitRepositoryFound) {
|
|
||||||
return response()->json(['message' => 'Repository not found.'], 404);
|
// Use direct API call to verify repository access instead of loading all repositories
|
||||||
|
// This is much faster and avoids timeouts for GitHub Apps with many repositories
|
||||||
|
$response = Http::GitHub($githubApp->api_url, $token)
|
||||||
|
->timeout(20)
|
||||||
|
->retry(3, 200, throw: false)
|
||||||
|
->get("/repos/{$gitRepository}");
|
||||||
|
|
||||||
|
if ($response->status() === 404 || $response->status() === 403) {
|
||||||
|
return response()->json(['message' => 'Repository not found or not accessible by the GitHub App.'], 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! $response->successful()) {
|
||||||
|
return response()->json(['message' => 'Failed to verify repository access: '.($response->json()['message'] ?? 'Unknown error')], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
$gitRepositoryFound = $response->json();
|
||||||
$repository_project_id = data_get($gitRepositoryFound, 'id');
|
$repository_project_id = data_get($gitRepositoryFound, 'id');
|
||||||
|
|
||||||
$application = new Application;
|
$application = new Application;
|
||||||
|
|||||||
Reference in New Issue
Block a user