Implement Gitea user connection foundation

This commit is contained in:
2026-03-26 08:56:52 +01:00
parent ec5b531e5e
commit 5f52d050ee
23 changed files with 1206 additions and 1 deletions
@@ -0,0 +1,83 @@
<?php
namespace App\Http\Requests\Settings;
use App\Actions\Git\GitProviderKey;
use App\Models\UserGitConnection;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
class UpdateUserGitConnectionRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return $this->user() !== null;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
/** @var UserGitConnection $gitConnection */
$gitConnection = $this->route('gitConnection');
return [
'api_token' => ['required', 'string', 'max:2048'],
'base_url' => [
'required',
'url:http,https',
'max:255',
Rule::unique('user_git_connections')
->ignore($gitConnection->id)
->where(fn ($query) => $query
->where('user_id', $this->user()->id)
->where('provider', $this->input('provider'))),
],
'provider' => ['required', Rule::in(array_map(
static fn (GitProviderKey $providerKey): string => $providerKey->value,
GitProviderKey::cases(),
))],
];
}
protected function prepareForValidation(): void
{
$this->merge([
'base_url' => $this->normalizedBaseUrl(),
'provider' => Str::lower(trim((string) $this->input('provider'))),
]);
}
public function apiToken(): string
{
return (string) $this->validated('api_token');
}
public function baseUrl(): string
{
return (string) $this->validated('base_url');
}
public function provider(): GitProviderKey
{
return GitProviderKey::from((string) $this->validated('provider'));
}
private function normalizedBaseUrl(): string
{
$baseUrl = Str::of((string) $this->input('base_url'))
->trim()
->rtrim('/')
->value();
return preg_replace('#/api/v1$#i', '', $baseUrl) ?? $baseUrl;
}
}