1
0
Fork 0
mirror of synced 2024-09-30 17:26:48 +13:00

PR review changes

This commit is contained in:
Matej Bačo 2023-08-11 18:44:05 +02:00
parent d219085196
commit f0125ac3bb
4 changed files with 16 additions and 49 deletions

View file

@ -108,17 +108,11 @@ $redeployVcs = function (Request $request, Document $function, Document $project
'activate' => true,
]));
$projectId = $project->getId();
$functionId = $function->getId();
$providerTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
$buildEvent = new Build();
$buildEvent
->setType(BUILD_TYPE_DEPLOYMENT)
->setResource($function)
->setDeployment($deployment)
->setProviderTargetUrl($providerTargetUrl)
->setTemplate($template)
->setProject($project)
->trigger();

View file

@ -201,8 +201,6 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
'activate' => $activate,
]));
$providerTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
if (!empty($providerCommitHash) && $function->getAttribute('providerSilentMode', false) === false) {
$functionName = $function->getAttribute('name');
$projectName = $project->getAttribute('name');
@ -212,6 +210,8 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
$providerRepositoryId = $resource->getAttribute('providerRepositoryId');
$repositoryName = $github->getRepositoryName($providerRepositoryId);
$owner = $github->getOwnerName($providerInstallationId);
$providerTargetUrl = $request->getProtocol() . '://' . $request->getHostname() . "/console/project-$projectId/functions/function-$functionId";
$github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, 'pending', $message, $providerTargetUrl, $name);
}
@ -229,8 +229,6 @@ $createGitDeployments = function (GitHub $github, string $providerInstallationId
->setResource($function)
->setProviderContribution($contribution)
->setDeployment($deployment)
->setProviderTargetUrl($providerTargetUrl)
->setProviderCommitHash($providerCommitHash)
->setProject($project)
->trigger();

View file

@ -49,8 +49,6 @@ class BuildsV1 extends Worker
$resource = new Document($this->args['resource'] ?? []);
$deployment = new Document($this->args['deployment'] ?? []);
$template = new Document($this->args['template'] ?? []);
$providerCommitHash = $this->args['providerCommitHash'] ?? '';
$providerTargetUrl = $this->args['providerTargetUrl'] ?? '';
$providerContribution = new Document($this->args['providerContribution'] ?? []);
switch ($type) {
@ -58,7 +56,7 @@ class BuildsV1 extends Worker
case BUILD_TYPE_RETRY:
Console::info('Creating build for deployment: ' . $deployment->getId());
$github = new GitHub($this->getCache());
$this->buildDeployment($github, $project, $resource, $deployment, $template, $providerCommitHash, $providerTargetUrl, $providerContribution);
$this->buildDeployment($github, $project, $resource, $deployment, $template, $providerContribution);
break;
default:
@ -72,7 +70,7 @@ class BuildsV1 extends Worker
* @throws \Utopia\Database\Exception\Structure
* @throws Throwable
*/
protected function buildDeployment(GitHub $github, Document $project, Document $function, Document $deployment, Document $template, string $providerCommitHash = '', string $providerTargetUrl = '', Document $providerContribution = null)
protected function buildDeployment(GitHub $github, Document $project, Document $function, Document $deployment, Document $template, Document $providerContribution = null)
{
global $register;
@ -149,6 +147,7 @@ class BuildsV1 extends Worker
$source = $deployment->getAttribute('path', '');
$installationId = $deployment->getAttribute('installationId', '');
$providerRepositoryId = $deployment->getAttribute('providerRepositoryId', '');
$providerCommitHash = $deployment->getAttribute('providerCommitHash', '');
$isVcsEnabled = $providerRepositoryId ? true : false;
$owner = '';
$repositoryName = '';
@ -278,7 +277,7 @@ class BuildsV1 extends Worker
$build = $dbForProject->updateDocument('builds', $build->getId(), $build->setAttribute('source', $source));
if ($isVcsEnabled) {
$this->runGitAction('processing', $github, $providerCommitHash, $owner, $repositoryName, $providerTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
$this->runGitAction('processing', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
}
}
}
@ -288,7 +287,7 @@ class BuildsV1 extends Worker
$build = $dbForProject->updateDocument('builds', $buildId, $build);
if ($isVcsEnabled) {
$this->runGitAction('building', $github, $providerCommitHash, $owner, $repositoryName, $providerTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
$this->runGitAction('building', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
}
/** Trigger Webhook */
@ -440,7 +439,7 @@ class BuildsV1 extends Worker
$build->setAttribute('logs', $response['output']);
if ($isVcsEnabled) {
$this->runGitAction('ready', $github, $providerCommitHash, $owner, $repositoryName, $providerTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
$this->runGitAction('ready', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
}
Console::success("Build id: $buildId created");
@ -472,7 +471,7 @@ class BuildsV1 extends Worker
Console::error($th->getMessage());
if ($isVcsEnabled) {
$this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $providerTargetUrl, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
$this->runGitAction('failed', $github, $providerCommitHash, $owner, $repositoryName, $project, $function, $deployment->getId(), $dbForProject, $dbForConsole);
}
} finally {
$build = $dbForProject->updateDocument('builds', $buildId, $build);
@ -508,7 +507,7 @@ class BuildsV1 extends Worker
->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)
protected function runGitAction(string $status, GitHub $github, string $providerCommitHash, string $owner, string $repositoryName, Document $project, Document $function, string $deploymentId, Database $dbForProject, Database $dbForConsole)
{
if ($function->getAttribute('providerSilentMode', false) === true) {
return;
@ -537,6 +536,12 @@ class BuildsV1 extends Worker
$name = "{$functionName} ({$projectName})";
$protocol = App::getEnv('_APP_OPTIONS_FORCE_HTTPS') == 'disabled' ? 'http' : 'https';
$hostname = App::getEnv('_APP_DOMAIN');
$functionId = $function->getId();
$projectId = $project->getId();
$providerTargetUrl = $protocol . '://' . $hostname . "/console/project-$projectId/functions/function-$functionId";
$github->updateCommitStatus($repositoryName, $providerCommitHash, $owner, $state, $message, $providerTargetUrl, $name);
}

View file

@ -11,8 +11,6 @@ class Build extends Event
protected ?Document $resource = null;
protected ?Document $deployment = null;
protected ?Document $template = null;
protected string $providerCommitHash = '';
protected string $providerTargetUrl = '';
protected ?Document $providerContribution = null;
public function __construct()
@ -33,32 +31,6 @@ class Build extends Event
return $this;
}
/**
* Sets commit SHA for the build event.
*
* @param string $providerCommitHash is the commit hash of the incoming commit
* @return self
*/
public function setProviderCommitHash(string $providerCommitHash): self
{
$this->providerCommitHash = $providerCommitHash;
return $this;
}
/**
* Sets redirect target url for the deployment
*
* @param string $providerTargetUrl is the url that is to be set
* @return self
*/
public function setProviderTargetUrl(string $providerTargetUrl): self
{
$this->providerTargetUrl = $providerTargetUrl;
return $this;
}
/**
* Sets resource document for the build event.
*
@ -155,8 +127,6 @@ class Build extends Event
'deployment' => $this->deployment,
'type' => $this->type,
'template' => $this->template,
'providerCommitHash' => $this->providerCommitHash,
'providerTargetUrl' => $this->providerTargetUrl,
'providerContribution' => $this->providerContribution
]);
}