Implement package-based framework detection

This commit is contained in:
Matej Bačo
2025-10-22 15:28:49 +02:00
parent a5486128d4
commit d787408e1d
4 changed files with 45 additions and 26 deletions
+30 -11
View File
@@ -66,6 +66,7 @@ use Utopia\Validator\Boolean;
use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
use Utopia\VCS\Adapter\Git\GitHub;
use Utopia\VCS\Exception\FileNotFound;
use Utopia\VCS\Exception\RepositoryNotFound;
use function Swoole\Coroutine\batch;
@@ -827,7 +828,7 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
$languages = $github->listRepositoryLanguages($owner, $repositoryName);
$detector = new Packager();
foreach($files as $file) {
foreach ($files as $file) {
$detector->addInput($file);
}
$detector
@@ -839,6 +840,14 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
$packager = !\is_null($detection) ? $detection->getName() : 'npm';
if ($type === 'framework') {
$packages = '';
try {
$response = $github->getRepositoryContent($owner, $repositoryName, \rtrim($providerRootDirectory, '/') . '/package.json');
$packages = $response['content'] ?? '';
} catch (FileNotFound $e) {
// Continue detection without package.json
}
$output = new Document([
'framework' => '',
'installCommand' => '',
@@ -847,10 +856,11 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
]);
$detector = new Framework($packager);
foreach($files as $file) {
$detector->addInput($packages, Framework::INPUT_PACKAGES);
foreach ($files as $file) {
$detector->addInput($file, Framework::INPUT_FILE);
}
// TODO: Add package contents
$detector
@@ -903,8 +913,8 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
foreach ($strategies as $strategy) {
$detector = new Runtime($strategy, $packager);
if($strategy === Strategy::LANGUAGES) {
if ($strategy === Strategy::LANGUAGES) {
foreach ($languages as $language) {
$detector->addInput($language);
}
@@ -913,7 +923,7 @@ App::post('/v1/vcs/github/installations/:installationId/detections')
$detector->addInput($file);
}
}
$detector
->addOption(new Node())
->addOption(new Bun())
@@ -1033,11 +1043,20 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
$packager = !\is_null($detection) ? $detection->getName() : 'npm';
if ($type === 'framework') {
$packages = '';
try {
$response = $github->getRepositoryContent($repo['organization'], $repo['name'], 'package.json');
$packages = $response['content'] ?? '';
} catch (FileNotFound $e) {
// Continue detection without package.json
}
$frameworkDetector = new Framework($packager);
foreach($files as $file) {
$frameworkDetector->addInput($packages, Framework::INPUT_PACKAGES);
foreach ($files as $file) {
$frameworkDetector->addInput($file, Framework::INPUT_FILE);
}
// TODO: Add package contents
$frameworkDetector
@@ -1080,12 +1099,12 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories')
foreach ($strategies as $strategy) {
$detector = new Runtime($strategy === Strategy::LANGUAGES ? $languages : $files, $strategy, $packager);
if($strategy === Strategy::LANGUAGES) {
foreach($languages as $language) {
if ($strategy === Strategy::LANGUAGES) {
foreach ($languages as $language) {
$detector->addInput($language);
}
} else {
foreach($files as $file) {
foreach ($files as $file) {
$detector->addInput($file);
}
}
+1 -1
View File
@@ -74,7 +74,7 @@
"utopia-php/swoole": "0.8.*",
"utopia-php/system": "0.9.*",
"utopia-php/telemetry": "0.1.*",
"utopia-php/vcs": "0.11.*",
"utopia-php/vcs": "0.12.*",
"utopia-php/websocket": "0.3.*",
"matomo/device-detector": "6.4.*",
"dragonmantank/cron-expression": "3.4.*",
Generated
+13 -13
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "560ae413f106013aae015459df2babe1",
"content-hash": "6a63e31f09d48370045c7afcfb7fd3dd",
"packages": [
{
"name": "adhocore/jwt",
@@ -4395,16 +4395,16 @@
},
{
"name": "utopia-php/migration",
"version": "1.3.1",
"version": "1.3.2",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/migration.git",
"reference": "b6985b235ab64f07a6b88569e20cf9b2df7d838c"
"reference": "f5c1d2cae764290766a4c2d1546c1d51de95b67f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/b6985b235ab64f07a6b88569e20cf9b2df7d838c",
"reference": "b6985b235ab64f07a6b88569e20cf9b2df7d838c",
"url": "https://api.github.com/repos/utopia-php/migration/zipball/f5c1d2cae764290766a4c2d1546c1d51de95b67f",
"reference": "f5c1d2cae764290766a4c2d1546c1d51de95b67f",
"shasum": ""
},
"require": {
@@ -4444,9 +4444,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/migration/issues",
"source": "https://github.com/utopia-php/migration/tree/1.3.1"
"source": "https://github.com/utopia-php/migration/tree/1.3.2"
},
"time": "2025-10-21T08:13:54+00:00"
"time": "2025-10-22T12:30:47+00:00"
},
{
"name": "utopia-php/mongo",
@@ -5095,16 +5095,16 @@
},
{
"name": "utopia-php/vcs",
"version": "0.11.0",
"version": "0.12.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/vcs.git",
"reference": "0e665eaa7d906168525bf6aac50b6bcc3e4fe528"
"reference": "28457cf347972c4ec95d3ca77776a4921364a665"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/0e665eaa7d906168525bf6aac50b6bcc3e4fe528",
"reference": "0e665eaa7d906168525bf6aac50b6bcc3e4fe528",
"url": "https://api.github.com/repos/utopia-php/vcs/zipball/28457cf347972c4ec95d3ca77776a4921364a665",
"reference": "28457cf347972c4ec95d3ca77776a4921364a665",
"shasum": ""
},
"require": {
@@ -5138,9 +5138,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/vcs/issues",
"source": "https://github.com/utopia-php/vcs/tree/0.11.0"
"source": "https://github.com/utopia-php/vcs/tree/0.12.0"
},
"time": "2025-07-23T13:54:58+00:00"
"time": "2025-10-22T12:58:29+00:00"
},
{
"name": "utopia-php/websocket",
@@ -875,7 +875,7 @@ class Builds extends Action
$files = \array_map(fn ($file) => \str_starts_with($file, './') ? \substr($file, 2) : $file, $files); // Remove beginning ./
$detector = new Rendering($resource->getAttribute('framework', ''));
foreach($files as $file) {
foreach ($files as $file) {
$detector->addInput($file);
}
$detector