API Feature (#334)

This commit is contained in:
Saeed Vaziry
2024-11-01 16:49:57 +01:00
committed by GitHub
parent da7b24640e
commit 417bf73e44
143 changed files with 36520 additions and 586 deletions

View File

@ -2,9 +2,8 @@
namespace App\Web\Pages\Settings\SourceControls\Actions;
use App\Actions\SourceControl\ConnectSourceControl;
use App\Actions\SourceControl\EditSourceControl;
use App\Enums\SourceControl;
use App\Models\SourceControl;
use Exception;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\TextInput;
@ -13,30 +12,27 @@
class Edit
{
public static function form(): array
public static function form(SourceControl $sourceControl): array
{
return [
TextInput::make('name')
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['name']),
->rules(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['name']),
TextInput::make('token')
->label('API Key')
->validationAttribute('API Key')
->visible(fn ($get) => in_array($get('provider'), [
SourceControl::GITHUB,
SourceControl::GITLAB,
]))
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['token']),
->visible(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['token'] ?? false)
->rules(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['token']),
TextInput::make('url')
->label('URL (optional)')
->visible(fn ($get) => $get('provider') == SourceControl::GITLAB)
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['url'])
->visible(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['url'] ?? false)
->rules(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['url'])
->helperText('If you run a self-managed gitlab enter the url here, leave empty to use gitlab.com'),
TextInput::make('username')
->visible(fn ($get) => $get('provider') == SourceControl::BITBUCKET)
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['username']),
->visible(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['username'] ?? false)
->rules(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['username']),
TextInput::make('password')
->visible(fn ($get) => $get('provider') == SourceControl::BITBUCKET)
->rules(fn (Get $get) => ConnectSourceControl::rules($get())['password']),
->visible(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['password'] ?? false)
->rules(fn (Get $get) => EditSourceControl::rules($sourceControl, $get())['password']),
Checkbox::make('global')
->label('Is Global (Accessible in all projects)'),
];
@ -45,10 +41,10 @@ public static function form(): array
/**
* @throws Exception
*/
public static function action(\App\Models\SourceControl $sourceControl, array $data): void
public static function action(SourceControl $sourceControl, array $data): void
{
try {
app(EditSourceControl::class)->edit($sourceControl, auth()->user(), $data);
app(EditSourceControl::class)->edit($sourceControl, auth()->user()->currentProject, $data);
} catch (Exception $e) {
Notification::make()
->title($e->getMessage())