env variables validation

This commit is contained in:
Your Name
2023-11-18 19:57:41 +02:00
parent 5c99cc34d0
commit 61461519e1
3 changed files with 27 additions and 1 deletions

View File

@@ -1,4 +1,5 @@
GITEA_INSTANCE_BASE_URL="https://gitea.example.com"
GITEA_ACCESS_TOKEN="access_token"
GITEA_OWNER="owner"
GITEA_REPOSITORY="repository"
GITEA_REPOSITORY="repository"
GITEA_PACKAGE_REGISTRY="composer"

View File

@@ -10,6 +10,7 @@ services:
GITEA_ACCESS_TOKEN: ${GITEA_ACCESS_TOKEN}
GITEA_OWNER: ${GITEA_OWNER}
GITEA_REPOSITORY: ${GITEA_REPOSITORY}
GITEA_PACKAGE_REGISTRY: ${GITEA_PACKAGE_REGISTRY}
volumes:
- ./src:/var/src
networks:

View File

@@ -104,6 +104,30 @@ function showTerminalMessage (string $message = '', string $color = ''): void
try {
if (empty(\getenv('GITEA_INSTANCE_BASE_URL'))) {
throw new \Exception('GITEA_INSTANCE_BASE_URL empty');
}
if (empty(\getenv('GITEA_ACCESS_TOKEN'))) {
throw new \Exception('GITEA_ACCESS_TOKEN empty');
}
if (empty(\getenv('GITEA_OWNER'))) {
throw new \Exception('GITEA_OWNER empty');
}
if (empty(\getenv('GITEA_REPOSITORY'))) {
throw new \Exception('GITEA_REPOSITORY empty');
}
if (empty(\getenv('GITEA_PACKAGE_REGISTRY'))) {
throw new \Exception('GITEA_PACKAGE_REGISTRY empty');
}
if (!\in_array(\getenv('GITEA_PACKAGE_REGISTRY'), ['composer'])) {
throw new \Exception('Package registry {' . \getenv('GITEA_PACKAGE_REGISTRY') . '} is not supported');
}
$response = sendRequest('GET', '/api/v1/user');
$data = responseEncode($response);