1
0
Fork 0
mirror of synced 2024-06-30 12:10:51 +12:00

Added exception for repo creation + small fixes

This commit is contained in:
Khushboo Verma 2023-08-17 19:24:57 +05:30
parent 3a6f10fa62
commit 4285d99f08
5 changed files with 27 additions and 9 deletions

View file

@ -385,6 +385,11 @@ return [
'description' => 'External contribution is already authorized.',
'code' => 409,
],
Exception::GENERAL_PROVIDER_FAILURE => [
'name' => Exception::GENERAL_PROVIDER_FAILURE,
'description' => 'VCS (Version Control System) provider failed to proccess the request.',
'code' => 400,
],
/** Functions */
Exception::FUNCTION_NOT_FOUND => [

@ -1 +1 @@
Subproject commit a1ec99e86331e5eeb56614c69f50e83f334deafb
Subproject commit c4331ea10dce0cbf403cae9aec8273f2d003ba2e

View file

@ -36,6 +36,7 @@ use Utopia\Detector\Adapter\Swift;
use Utopia\Detector\Detector;
use Utopia\Validator\Boolean;
use function PHPUnit\Framework\throwException;
use function Swoole\Coroutine\batch;
$createGitDeployments = function (GitHub $github, string $providerInstallationId, array $repositories, string $providerBranch, string $providerBranchUrl, string $providerRepositoryName, string $providerRepositoryUrl, string $providerRepositoryOwner, string $providerCommitHash, string $providerCommitAuthor, string $providerCommitAuthorUrl, string $providerCommitMessage, string $providerCommitUrl, string $providerPullRequestId, bool $external, Database $dbForConsole, callable $getProjectDB, Request $request) {
@ -702,7 +703,11 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories')
$dbForConsole->updateDocument('identities', $identity->getId(), $identity);
}
$repository = $oauth2->createRepository($accessToken, $name, $private);
try {
$repository = $oauth2->createRepository($accessToken, $name, $private);
} catch (Exception $exception) {
throw new Exception(Exception::GENERAL_PROVIDER_FAILURE, "GitHub failed to process the request: " . $exception->getMessage());
}
} else {
$providerInstallationId = $installation->getAttribute('providerInstallationId');
$privateKey = App::getEnv('_APP_VCS_GITHUB_PRIVATE_KEY');
@ -710,7 +715,11 @@ App::post('/v1/vcs/github/installations/:installationId/providerRepositories')
$github->initializeVariables($providerInstallationId, $privateKey, $githubAppId);
$owner = $github->getOwnerName($providerInstallationId);
$repository = $github->createRepository($owner, $name, $private);
try {
$repository = $github->createRepository($owner, $name, $private);
} catch (Exception $exception) {
throw new Exception(Exception::GENERAL_PROVIDER_FAILURE, "GitHub failed to process the request: " . $exception->getMessage());
}
}
if (isset($repository['message'])) {

View file

@ -454,12 +454,15 @@ class BuildsV1 extends Worker
/** Update function schedule */
$dbForConsole = $this->getConsoleDB();
// Inform scheduler if function is still active
$schedule = $dbForConsole->getDocument('schedules', $function->getAttribute('scheduleId'));
$schedule
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('schedule', $function->getAttribute('schedule'))
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
$scheduleId = $function->getAttribute('scheduleId', '');
if (!empty($scheduleId)) {
$schedule = $dbForConsole->getDocument('schedules', $scheduleId);
$schedule
->setAttribute('resourceUpdatedAt', DateTime::now())
->setAttribute('schedule', $function->getAttribute('schedule'))
->setAttribute('active', !empty($function->getAttribute('schedule')) && !empty($function->getAttribute('deployment')));
Authorization::skip(fn () => $dbForConsole->updateDocument('schedules', $schedule->getId(), $schedule));
}
} catch (\Throwable $th) {
$endTime = DateTime::now();
$durationEnd = \microtime(true);

View file

@ -121,6 +121,7 @@ class Exception extends \Exception
public const PROVIDER_REPOSITORY_NOT_FOUND = 'provider_repository_not_found';
public const REPOSITORY_NOT_FOUND = 'repository_not_found';
public const PROVIDER_CONTRIBUTION_CONFLICT = 'provider_contribution_conflict';
public const GENERAL_PROVIDER_FAILURE = 'general_provider_failure';
/** Functions */
public const FUNCTION_NOT_FOUND = 'function_not_found';