Manage redirects, missing URLs, repositories and settings through the API
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
50
app/Http/Requests/Api/V1/RepositoryRequest.php
Normal file
50
app/Http/Requests/Api/V1/RepositoryRequest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Requests\Api\V1;
|
||||
|
||||
use App\Enums\GitProvider;
|
||||
use App\Models\Repository;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* The panel's repository form, as rules. The synced columns are not here on
|
||||
* purpose: nothing a caller sends may fake a repository's numbers.
|
||||
*/
|
||||
class RepositoryRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$repository = $this->route('repository');
|
||||
$creating = ! $repository instanceof Repository;
|
||||
$sometimes = $creating ? 'required' : 'sometimes';
|
||||
|
||||
$provider = $this->input('provider', $repository?->provider?->value);
|
||||
|
||||
return [
|
||||
'provider' => [$sometimes, Rule::enum(GitProvider::class)],
|
||||
'full_name' => [
|
||||
$sometimes,
|
||||
'string',
|
||||
'max:255',
|
||||
'regex:/^[\w.-]+\/[\w.-]+$|^[\w.-]+$/',
|
||||
Rule::unique('repositories', 'full_name')
|
||||
->ignore($repository?->id)
|
||||
->where('provider', $provider),
|
||||
],
|
||||
'project_id' => ['sometimes', 'nullable', 'integer', Rule::exists('projects', 'id')->whereNull('deleted_at')],
|
||||
'is_primary' => ['sometimes', 'boolean'],
|
||||
'show_publicly' => ['sometimes', 'boolean'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user