lasthourcloud/app/Http/Livewire/Project/Application/Source.php

46 lines
1.3 KiB
PHP
Raw Normal View History

2023-04-19 10:42:15 +00:00
<?php
2023-04-25 09:01:56 +00:00
namespace App\Http\Livewire\Project\Application;
2023-04-19 10:42:15 +00:00
use App\Models\Application;
2023-06-12 12:38:32 +00:00
use App\Models\PrivateKey;
2023-04-19 10:42:15 +00:00
use Livewire\Component;
class Source extends Component
{
public $applicationId;
public Application $application;
2023-06-12 12:38:32 +00:00
public $private_keys;
2023-04-19 10:42:15 +00:00
protected $rules = [
'application.git_repository' => 'required',
'application.git_branch' => 'required',
'application.git_commit_sha' => 'nullable',
];
2023-06-12 12:38:32 +00:00
private function get_private_keys()
{
$this->private_keys = PrivateKey::whereTeamId(session('currentTeam')->id)->get()->reject(function ($key) {
return $key->id == $this->application->private_key_id;
});
}
public function mount()
{
$this->get_private_keys();
}
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-05-10 10:22:27 +00:00
public function submit()
{
$this->validate();
if (!$this->application->git_commit_sha) {
$this->application->git_commit_sha = 'HEAD';
}
$this->application->save();
$this->emit('saved', 'Application source updated!');
}
2023-04-19 10:42:15 +00:00
}