mirror of
https://github.com/vitodeploy/vito.git
synced 2025-07-01 14:06:15 +00:00
init
This commit is contained in:
35
app/Actions/SourceControl/ConnectSourceControl.php
Normal file
35
app/Actions/SourceControl/ConnectSourceControl.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\SourceControl;
|
||||
|
||||
use App\Models\SourceControl;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class ConnectSourceControl
|
||||
{
|
||||
public function connect(string $provider, array $input): void
|
||||
{
|
||||
$sourceControl = SourceControl::query()
|
||||
->where('provider', $provider)
|
||||
->first();
|
||||
if (! $sourceControl) {
|
||||
$sourceControl = new SourceControl([
|
||||
'provider' => $provider,
|
||||
]);
|
||||
}
|
||||
|
||||
if (! $input['token']) {
|
||||
$sourceControl->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$sourceControl->access_token = $input['token'];
|
||||
if (! $sourceControl->provider()->connect()) {
|
||||
throw ValidationException::withMessages([
|
||||
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $provider]),
|
||||
]);
|
||||
}
|
||||
$sourceControl->save();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user