2022-04-19 13:13:55 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Appwrite\Event;
|
|
|
|
|
|
|
|
|
|
use Resque;
|
|
|
|
|
use Utopia\Database\Document;
|
|
|
|
|
|
|
|
|
|
class Build extends Event
|
|
|
|
|
{
|
|
|
|
|
protected string $type = '';
|
|
|
|
|
protected ?Document $resource = null;
|
|
|
|
|
protected ?Document $deployment = null;
|
2023-07-28 07:41:26 +00:00
|
|
|
protected ?Document $vcsTemplate = null;
|
|
|
|
|
protected string $vcsCommitHash = '';
|
|
|
|
|
protected string $vcsTargetUrl = '';
|
2023-06-28 11:31:35 +00:00
|
|
|
protected ?Document $vcsContribution = null;
|
2022-04-19 13:13:55 +00:00
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct(Event::BUILDS_QUEUE_NAME, Event::BUILDS_CLASS_NAME);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-17 12:12:21 +00:00
|
|
|
/**
|
|
|
|
|
* Sets template for the build event.
|
|
|
|
|
*
|
2023-07-28 07:41:26 +00:00
|
|
|
* @param Document $vcsTemplate
|
2023-06-17 12:12:21 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2023-07-28 07:41:26 +00:00
|
|
|
public function setVcsTemplate(Document $vcsTemplate): self
|
2023-06-17 12:12:21 +00:00
|
|
|
{
|
2023-07-28 07:41:26 +00:00
|
|
|
$this->vcsTemplate = $vcsTemplate;
|
2023-06-17 12:12:21 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-22 10:58:13 +00:00
|
|
|
/**
|
|
|
|
|
* Sets commit SHA for the build event.
|
|
|
|
|
*
|
2023-07-28 07:41:26 +00:00
|
|
|
* @param string $vcsCommitHash is the commit hash of the incoming commit
|
2023-05-22 10:58:13 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2023-07-28 07:41:26 +00:00
|
|
|
public function setVcsCommitHash(string $vcsCommitHash): self
|
2023-05-22 10:58:13 +00:00
|
|
|
{
|
2023-07-28 07:41:26 +00:00
|
|
|
$this->vcsCommitHash = $vcsCommitHash;
|
2023-05-22 10:58:13 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets redirect target url for the deployment
|
|
|
|
|
*
|
2023-07-28 07:41:26 +00:00
|
|
|
* @param string $vcsTargetUrl is the url that is to be set
|
2023-05-22 10:58:13 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
2023-07-28 07:41:26 +00:00
|
|
|
public function setVcsTargetUrl(string $vcsTargetUrl): self
|
2023-05-22 10:58:13 +00:00
|
|
|
{
|
2023-07-28 07:41:26 +00:00
|
|
|
$this->vcsTargetUrl = $vcsTargetUrl;
|
2023-05-22 10:58:13 +00:00
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 13:13:55 +00:00
|
|
|
/**
|
|
|
|
|
* Sets resource document for the build event.
|
|
|
|
|
*
|
2022-05-10 12:31:20 +00:00
|
|
|
* @param Document $resource
|
2022-04-19 13:13:55 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setResource(Document $resource): self
|
|
|
|
|
{
|
|
|
|
|
$this->resource = $resource;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-28 11:31:35 +00:00
|
|
|
/**
|
|
|
|
|
* Sets custom owner and repository for VCS clone command during build
|
|
|
|
|
*
|
|
|
|
|
* @param Document $owner
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setVcsContribution(Document $vcsContribution): self
|
|
|
|
|
{
|
|
|
|
|
$this->vcsContribution = $vcsContribution;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-19 13:13:55 +00:00
|
|
|
/**
|
|
|
|
|
* Returns set resource document for the build event.
|
|
|
|
|
*
|
2022-05-23 14:54:50 +00:00
|
|
|
* @return null|Document
|
2022-04-19 13:13:55 +00:00
|
|
|
*/
|
|
|
|
|
public function getResource(): ?Document
|
|
|
|
|
{
|
|
|
|
|
return $this->resource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets deployment for the build event.
|
|
|
|
|
*
|
2022-05-10 12:31:20 +00:00
|
|
|
* @param Document $deployment
|
2022-04-19 13:13:55 +00:00
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setDeployment(Document $deployment): self
|
|
|
|
|
{
|
|
|
|
|
$this->deployment = $deployment;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns set deployment for the build event.
|
|
|
|
|
*
|
2022-05-10 12:31:20 +00:00
|
|
|
* @return null|Document
|
2022-04-19 13:13:55 +00:00
|
|
|
*/
|
|
|
|
|
public function getDeployment(): ?Document
|
|
|
|
|
{
|
|
|
|
|
return $this->deployment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets type for the build event.
|
|
|
|
|
*
|
|
|
|
|
* @param string $type Can be `BUILD_TYPE_DEPLOYMENT` or `BUILD_TYPE_RETRY`.
|
|
|
|
|
* @return self
|
|
|
|
|
*/
|
|
|
|
|
public function setType(string $type): self
|
|
|
|
|
{
|
|
|
|
|
$this->type = $type;
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns set type for the function event.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getType(): string
|
|
|
|
|
{
|
|
|
|
|
return $this->type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Executes the function event and sends it to the functions worker.
|
|
|
|
|
*
|
|
|
|
|
* @return string|bool
|
|
|
|
|
* @throws \InvalidArgumentException
|
|
|
|
|
*/
|
|
|
|
|
public function trigger(): string|bool
|
|
|
|
|
{
|
|
|
|
|
return Resque::enqueue($this->queue, $this->class, [
|
|
|
|
|
'project' => $this->project,
|
|
|
|
|
'resource' => $this->resource,
|
|
|
|
|
'deployment' => $this->deployment,
|
2023-05-22 10:58:13 +00:00
|
|
|
'type' => $this->type,
|
2023-07-28 07:41:26 +00:00
|
|
|
'vcsTemplate' => $this->vcsTemplate,
|
|
|
|
|
'vcsCommitHash' => $this->vcsCommitHash,
|
|
|
|
|
'vcsTargetUrl' => $this->vcsTargetUrl,
|
2023-06-28 11:31:35 +00:00
|
|
|
'vcsContribution' => $this->vcsContribution
|
2022-04-19 13:13:55 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|