diff --git a/app/console b/app/console index aa5abe03b5..55ac069437 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit aa5abe03b547b333c53acfc345d9e03842cc1936 +Subproject commit 55ac06943785fbf554b5b7d00bd0f5b4237fc4b2 diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index f249e78578..a0933d17e4 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -64,7 +64,17 @@ $redeployVcs = function (Request $request, Document $function, Document $project $authorUrl = "https://github.com/$owner"; $repositoryUrl = "https://github.com/$owner/$repositoryName"; $branchUrl = "https://github.com/$owner/$repositoryName/tree/$providerBranch"; - $commitDetails = $github->getLatestCommit($owner, $repositoryName, $providerBranch); + + $commitDetails = []; + if (!$template->isEmpty()) { + try { + $commitDetails = $github->getLatestCommit($owner, $repositoryName, $providerBranch); + } catch (\Throwable $error) { + Console::warning('Failed to get latest commit details'); + Console::warning($error->getMessage()); + Console::warning($error->getTraceAsString()); + } + } $deployment = $dbForProject->createDocument('deployments', new Document([ '$id' => $deploymentId, diff --git a/app/workers/builds.php b/app/workers/builds.php index fb87db63a5..8a3a2e3742 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -231,6 +231,31 @@ class BuildsV1 extends Worker } $providerCommitHash = \trim($stdout); + $authorUrl = "https://github.com/$cloneOwner"; + + $deployment->setAttribute('providerCommitHash', $providerCommitHash ?? ''); + $deployment->setAttribute('providerCommitAuthorUrl', $authorUrl); + $deployment->setAttribute('providerCommitAuthor', 'Appwrite'); + $deployment->setAttribute('providerCommitMessage', "Create '" . $function->getAttribute('name', '') . "' function"); + $deployment->setAttribute('providerCommitUrl', "https://github.com/$cloneOwner/$cloneRepository/commit/$providerCommitHash"); + $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), $deployment); + + /** + * Send realtime Event + */ + $target = Realtime::fromPayload( + // Pass first, most verbose event pattern + event: $allEvents[0], + payload: $build, + project: $project + ); + Realtime::send( + projectId: 'console', + payload: $build->getArrayCopy(), + events: $allEvents, + channels: $target['channels'], + roles: $target['roles'] + ); } Console::execute('tar --exclude code.tar.gz -czf /tmp/builds/' . $buildId . '/code.tar.gz -C /tmp/builds/' . $buildId . '/code' . (empty($rootDirectory) ? '' : '/' . $rootDirectory) . ' .', '', $stdout, $stderr); @@ -482,8 +507,7 @@ class BuildsV1 extends Worker ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS), 1) // per function ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_STORAGE), $build->getAttribute('size', 0)) ->addMetric(str_replace('{functionInternalId}', $function->getInternalId(), METRIC_FUNCTION_ID_BUILDS_COMPUTE), (int)$build->getAttribute('duration', 0) * 1000) - ->trigger() - ; + ->trigger(); } protected function runGitAction(string $status, GitHub $github, string $providerCommitHash, string $owner, string $repositoryName, string $providerTargetUrl, Document $project, Document $function, string $deploymentId, Database $dbForProject, Database $dbForConsole) @@ -543,7 +567,7 @@ class BuildsV1 extends Worker try { $comment = new Comment(); $comment->parseComment($github->getComment($owner, $repositoryName, $commentId)); - $comment->addBuild($project, $function, $status, $deployment->getId(), [ 'type' => 'logs' ]); + $comment->addBuild($project, $function, $status, $deployment->getId(), ['type' => 'logs']); $github->updateComment($owner, $repositoryName, $commentId, $comment->generateComment()); } catch (\Exception $e) { $error = $e; diff --git a/src/Appwrite/Auth/OAuth2.php b/src/Appwrite/Auth/OAuth2.php index c737e183f8..f7dc1d50a1 100644 --- a/src/Appwrite/Auth/OAuth2.php +++ b/src/Appwrite/Auth/OAuth2.php @@ -208,7 +208,7 @@ abstract class OAuth2 \curl_close($ch); - if ($code != 200) { + if ($code >= 400) { throw new Exception($response, $code); }