2023-04-19 12:42:15 +02:00
|
|
|
<?php
|
|
|
|
|
2023-12-07 19:06:32 +01:00
|
|
|
namespace App\Livewire\Project\Application;
|
2023-04-19 12:42:15 +02:00
|
|
|
|
|
|
|
use App\Models\Application;
|
2023-06-12 14:38:32 +02:00
|
|
|
use App\Models\PrivateKey;
|
2023-04-19 12:42:15 +02:00
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Source extends Component
|
|
|
|
{
|
|
|
|
public $applicationId;
|
|
|
|
public Application $application;
|
2023-06-12 14:38:32 +02:00
|
|
|
public $private_keys;
|
2023-04-19 12:42:15 +02:00
|
|
|
protected $rules = [
|
|
|
|
'application.git_repository' => 'required',
|
|
|
|
'application.git_branch' => 'required',
|
|
|
|
'application.git_commit_sha' => 'nullable',
|
|
|
|
];
|
2023-06-16 12:35:40 +02:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'application.git_repository' => 'repository',
|
|
|
|
'application.git_branch' => 'branch',
|
|
|
|
'application.git_commit_sha' => 'commit sha',
|
|
|
|
];
|
2023-08-08 11:51:36 +02:00
|
|
|
|
|
|
|
public function mount()
|
|
|
|
{
|
|
|
|
$this->get_private_keys();
|
|
|
|
}
|
|
|
|
|
2023-06-12 14:38:32 +02:00
|
|
|
private function get_private_keys()
|
|
|
|
{
|
2023-08-22 17:44:49 +02:00
|
|
|
$this->private_keys = PrivateKey::whereTeamId(currentTeam()->id)->get()->reject(function ($key) {
|
2023-06-12 14:38:32 +02:00
|
|
|
return $key->id == $this->application->private_key_id;
|
|
|
|
});
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-06-12 14:38:32 +02:00
|
|
|
public function setPrivateKey(int $private_key_id)
|
|
|
|
{
|
|
|
|
$this->application->private_key_id = $private_key_id;
|
|
|
|
$this->application->save();
|
|
|
|
$this->application->refresh();
|
|
|
|
$this->get_private_keys();
|
|
|
|
}
|
2023-08-08 11:51:36 +02:00
|
|
|
|
2023-05-10 12:22:27 +02:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
if (!$this->application->git_commit_sha) {
|
|
|
|
$this->application->git_commit_sha = 'HEAD';
|
|
|
|
}
|
|
|
|
$this->application->save();
|
2023-12-07 19:06:32 +01:00
|
|
|
$this->dispatch('success', 'Application source updated!');
|
2023-05-10 12:22:27 +02:00
|
|
|
}
|
2023-04-19 12:42:15 +02:00
|
|
|
}
|