diff --git a/app/controllers/api/vcs.php b/app/controllers/api/vcs.php index fd4d04cbd0..2ac6cd0b26 100644 --- a/app/controllers/api/vcs.php +++ b/app/controllers/api/vcs.php @@ -966,14 +966,14 @@ App::post('/v1/vcs/github/installations/:installationId/detections') } $wg = new WaitGroup(); - $envNames = []; + $envs = []; foreach ($files as $file) { if (!(\str_starts_with($file, '.env'))) { continue; } $wg->add(); - go(function () use ($github, $owner, $repositoryName, $providerRootDirectory, $file, $wg, &$envNames) { + go(function () use ($github, $owner, $repositoryName, $providerRootDirectory, $file, $wg, &$envs) { try { $contentResponse = $github->getRepositoryContent($owner, $repositoryName, \rtrim($providerRootDirectory, '/') . '/' . $file); $envFile = $contentResponse['content'] ?? ''; @@ -982,8 +982,9 @@ App::post('/v1/vcs/github/installations/:installationId/detections') foreach ($envLines as $line) { $parts = \explode('=', $line, 2); $envName = \trim($parts[0] ?? ''); + $envValue = \trim($parts[1] ?? ''); if (!empty($envName)) { - $envNames[] = $envName; + $envs[$envName] = $envValue; } } } finally { @@ -993,7 +994,15 @@ App::post('/v1/vcs/github/installations/:installationId/detections') } $wg->wait(); - $output->setAttribute('variables', \array_unique($envNames)); + $variables = []; + foreach ($envs as $key => $value) { + $variables[] = [ + 'name' => $key, + 'value' => $value, + ]; + } + + $output->setAttribute('variables', $variables); $response->dynamic($output, $type === 'framework' ? Response::MODEL_DETECTION_FRAMEWORK : Response::MODEL_DETECTION_RUNTIME); }); @@ -1171,14 +1180,14 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories') } $wg = new WaitGroup(); - $envNames = []; + $envs = []; foreach ($files as $file) { if (!(\str_starts_with($file, '.env'))) { continue; } $wg->add(); - go(function () use ($github, $repo, $file, $wg, &$envNames) { + go(function () use ($github, $repo, $file, $wg, &$envs) { try { $contentResponse = $github->getRepositoryContent($repo['organization'], $repo['name'], $file); $envFile = $contentResponse['content'] ?? ''; @@ -1187,8 +1196,9 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories') foreach ($envLines as $line) { $parts = \explode('=', $line, 2); $envName = \trim($parts[0] ?? ''); + $envValue = \trim($parts[1] ?? ''); if (!empty($envName)) { - $envNames[] = $envName; + $envs[$envName] = $envValue; } } } finally { @@ -1198,7 +1208,13 @@ App::get('/v1/vcs/github/installations/:installationId/providerRepositories') } $wg->wait(); - $repo['variables'] = \array_unique($envNames); + $repo['variables'] = []; + foreach ($envs as $key => $value) { + $repo['variables'][] = [ + 'name' => $key, + 'value' => $value, + ]; + } return $repo; }; diff --git a/src/Appwrite/Utopia/Response.php b/src/Appwrite/Utopia/Response.php index b391f0ea72..19a451e2c0 100644 --- a/src/Appwrite/Utopia/Response.php +++ b/src/Appwrite/Utopia/Response.php @@ -59,6 +59,7 @@ use Appwrite\Utopia\Response\Model\Database; use Appwrite\Utopia\Response\Model\Deployment; use Appwrite\Utopia\Response\Model\DetectionFramework; use Appwrite\Utopia\Response\Model\DetectionRuntime; +use Appwrite\Utopia\Response\Model\DetectionVariable; use Appwrite\Utopia\Response\Model\DevKey; use Appwrite\Utopia\Response\Model\Document as ModelDocument; use Appwrite\Utopia\Response\Model\Error; @@ -316,6 +317,7 @@ class Response extends SwooleResponse public const MODEL_BRANCH = 'branch'; public const MODEL_BRANCH_LIST = 'branchList'; public const MODEL_DETECTION_FRAMEWORK = 'detectionFramework'; + public const MODEL_DETECTION_VARIABLE = 'detectionVariable'; public const MODEL_DETECTION_RUNTIME = 'detectionRuntime'; public const MODEL_VCS_CONTENT = 'vcsContent'; public const MODEL_VCS_CONTENT_LIST = 'vcsContentList'; @@ -563,6 +565,7 @@ class Response extends SwooleResponse ->setModel(new ProviderRepositoryRuntime()) ->setModel(new DetectionFramework()) ->setModel(new DetectionRuntime()) + ->setModel(new DetectionVariable()) ->setModel(new VcsContent()) ->setModel(new Branch()) ->setModel(new Runtime()) diff --git a/src/Appwrite/Utopia/Response/Model/Detection.php b/src/Appwrite/Utopia/Response/Model/Detection.php new file mode 100644 index 0000000000..007182d1e9 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/Detection.php @@ -0,0 +1,22 @@ +addRule('variables', [ + 'type' => Response::MODEL_DETECTION_VARIABLE, + 'description' => 'Environment variables found in .env files', + 'required' => false, + 'default' => [], + 'example' => new \stdClass(), + 'array' => true, + ]); + } +} diff --git a/src/Appwrite/Utopia/Response/Model/DetectionFramework.php b/src/Appwrite/Utopia/Response/Model/DetectionFramework.php index 899ad8766e..4cdf37bbcf 100644 --- a/src/Appwrite/Utopia/Response/Model/DetectionFramework.php +++ b/src/Appwrite/Utopia/Response/Model/DetectionFramework.php @@ -3,12 +3,13 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; -use Appwrite\Utopia\Response\Model; -class DetectionFramework extends Model +class DetectionFramework extends Detection { public function __construct() { + parent::__construct(); + $this ->addRule('framework', [ 'type' => self::TYPE_STRING, @@ -33,13 +34,6 @@ class DetectionFramework extends Model 'description' => 'Site Output Directory', 'default' => '', 'example' => 'dist', - ]) - ->addRule('variables', [ - 'type' => self::TYPE_STRING, - 'description' => 'Environment variables found in .env files', - 'default' => [], - 'array' => true, - 'example' => ['PORT', 'NODE_ENV'], ]); } diff --git a/src/Appwrite/Utopia/Response/Model/DetectionRuntime.php b/src/Appwrite/Utopia/Response/Model/DetectionRuntime.php index 20fde90491..1e63929092 100644 --- a/src/Appwrite/Utopia/Response/Model/DetectionRuntime.php +++ b/src/Appwrite/Utopia/Response/Model/DetectionRuntime.php @@ -3,12 +3,13 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; -use Appwrite\Utopia\Response\Model; -class DetectionRuntime extends Model +class DetectionRuntime extends Detection { public function __construct() { + parent::__construct(); + $this ->addRule('runtime', [ 'type' => self::TYPE_STRING, @@ -27,13 +28,6 @@ class DetectionRuntime extends Model 'description' => 'Function install and build commands', 'default' => '', 'example' => 'npm install && npm run build', - ]) - ->addRule('variables', [ - 'type' => self::TYPE_STRING, - 'description' => 'Environment variables found in .env files', - 'default' => [], - 'array' => true, - 'example' => ['PORT', 'NODE_ENV'], ]); } diff --git a/src/Appwrite/Utopia/Response/Model/DetectionVariable.php b/src/Appwrite/Utopia/Response/Model/DetectionVariable.php new file mode 100644 index 0000000000..a5a2d2acc0 --- /dev/null +++ b/src/Appwrite/Utopia/Response/Model/DetectionVariable.php @@ -0,0 +1,46 @@ +addRule('name', [ + 'type' => self::TYPE_STRING, + 'description' => 'Name of environment variable', + 'default' => '', + 'example' => 'NODE_ENV', + ]) + ->addRule('value', [ + 'type' => self::TYPE_STRING, + 'description' => 'Value of environment variable', + 'default' => '', + 'example' => 'production', + ]); + } + + /** + * Get Name + * + * @return string + */ + public function getName(): string + { + return 'DetectionVariable'; + } + + /** + * Get Type + * + * @return string + */ + public function getType(): string + { + return Response::MODEL_DETECTION_VARIABLE; + } +}