-
Notifications
You must be signed in to change notification settings - Fork 166
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* edit source control * assign project after creation * global and project scoped source controls
- Loading branch information
1 parent
e704a13
commit 179aefe
Showing
15 changed files
with
362 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace App\Actions\SourceControl; | ||
|
||
use App\Models\SourceControl; | ||
use App\Models\User; | ||
use Illuminate\Support\Facades\Validator; | ||
use Illuminate\Validation\ValidationException; | ||
|
||
class EditSourceControl | ||
{ | ||
public function edit(SourceControl $sourceControl, User $user, array $input): void | ||
{ | ||
$this->validate($input); | ||
|
||
$sourceControl->profile = $input['name']; | ||
$sourceControl->url = isset($input['url']) ? $input['url'] : null; | ||
$sourceControl->project_id = isset($input['global']) && $input['global'] ? null : $user->current_project_id; | ||
|
||
$this->validateProvider($sourceControl, $input); | ||
|
||
$sourceControl->provider_data = $sourceControl->provider()->createData($input); | ||
|
||
if (! $sourceControl->provider()->connect()) { | ||
throw ValidationException::withMessages([ | ||
'token' => __('Cannot connect to :provider or invalid token!', ['provider' => $sourceControl->provider] | ||
), | ||
]); | ||
} | ||
|
||
$sourceControl->save(); | ||
} | ||
|
||
/** | ||
* @throws ValidationException | ||
*/ | ||
private function validate(array $input): void | ||
{ | ||
$rules = [ | ||
'name' => [ | ||
'required', | ||
], | ||
]; | ||
Validator::make($input, $rules)->validate(); | ||
} | ||
|
||
/** | ||
* @throws ValidationException | ||
*/ | ||
private function validateProvider(SourceControl $sourceControl, array $input): void | ||
{ | ||
Validator::make($input, $sourceControl->provider()->createRules($input))->validate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
database/migrations/2024_05_07_184201_add_project_id_to_source_controls_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::table('source_controls', function (Blueprint $table) { | ||
$table->unsignedBigInteger('project_id')->nullable(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::table('source_controls', function (Blueprint $table) { | ||
$table->dropColumn('project_id'); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@props([ | ||
"disabled" => false, | ||
"id", | ||
"name", | ||
"value", | ||
]) | ||
|
||
<div class="flex items-center"> | ||
<input | ||
id="{{ $id }}" | ||
name="{{ $name }}" | ||
type="checkbox" | ||
value="{{ $value }}" | ||
{{ $attributes->merge(["disabled" => $disabled, "class" => "rounded border-gray-300 text-indigo-600 shadow-sm focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:focus:ring-indigo-600 dark:focus:ring-offset-gray-800"]) }} | ||
/> | ||
<label for="{{ $id }}" class="ms-2 text-sm font-medium text-gray-900 dark:text-gray-300"> | ||
{{ $slot }} | ||
</label> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.