refactor(previews): move preview domain generation logic to ApplicationPreview model for better encapsulation and consistency across webhook handlers
This commit is contained in:
@@ -50,6 +50,33 @@ class ApplicationPreview extends BaseModel
|
||||
return $this->belongsTo(Application::class);
|
||||
}
|
||||
|
||||
public function generate_preview_fqdn()
|
||||
{
|
||||
if (is_null($this->fqdn) && $this->application->fqdn) {
|
||||
if (str($this->application->fqdn)->contains(',')) {
|
||||
$url = Url::fromString(str($this->application->fqdn)->explode(',')[0]);
|
||||
$preview_fqdn = getFqdnWithoutPort(str($this->application->fqdn)->explode(',')[0]);
|
||||
} else {
|
||||
$url = Url::fromString($this->application->fqdn);
|
||||
if ($this->fqdn) {
|
||||
$preview_fqdn = getFqdnWithoutPort($this->fqdn);
|
||||
}
|
||||
}
|
||||
$template = $this->application->preview_url_template;
|
||||
$host = $url->getHost();
|
||||
$schema = $url->getScheme();
|
||||
$random = new Cuid2;
|
||||
$preview_fqdn = str_replace('{{random}}', $random, $template);
|
||||
$preview_fqdn = str_replace('{{domain}}', $host, $preview_fqdn);
|
||||
$preview_fqdn = str_replace('{{pr_id}}', $this->pull_request_id, $preview_fqdn);
|
||||
$preview_fqdn = "$schema://$preview_fqdn";
|
||||
$this->fqdn = $preview_fqdn;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function generate_preview_fqdn_compose()
|
||||
{
|
||||
$services = collect(json_decode($this->application->docker_compose_domains)) ?? collect();
|
||||
|
||||
Reference in New Issue
Block a user