Implement Gitea user connection foundation
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Actions\Git\GitProviderKey;
|
||||
use App\Models\User;
|
||||
use App\Models\UserGitConnection;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<UserGitConnection>
|
||||
*/
|
||||
class UserGitConnectionFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'account_login' => fake()->userName(),
|
||||
'account_name' => fake()->name(),
|
||||
'api_token' => 'gitea-token-'.fake()->uuid(),
|
||||
'base_url' => 'https://git.'.fake()->domainName(),
|
||||
'provider' => GitProviderKey::Gitea,
|
||||
'provider_user_id' => (string) fake()->numberBetween(1, 999_999),
|
||||
'user_id' => User::factory(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?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::create('user_git_connections', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('user_id')->constrained()->cascadeOnDelete();
|
||||
$table->string('provider');
|
||||
$table->string('base_url');
|
||||
$table->string('provider_user_id');
|
||||
$table->string('account_login');
|
||||
$table->string('account_name')->nullable();
|
||||
$table->text('api_token');
|
||||
$table->timestamps();
|
||||
|
||||
$table->unique(['user_id', 'provider', 'base_url']);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('user_git_connections');
|
||||
}
|
||||
};
|
||||
@@ -14,6 +14,7 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
$this->call([
|
||||
UserSeeder::class,
|
||||
UserGitConnectionSeeder::class,
|
||||
ProjectSeeder::class,
|
||||
BoardColumnSeeder::class,
|
||||
ProjectTicketMetadataSeeder::class,
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Actions\Git\GitProviderKey;
|
||||
use App\Models\User;
|
||||
use App\Models\UserGitConnection;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class UserGitConnectionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$firstUser = User::query()->orderBy('id')->first();
|
||||
|
||||
if ($firstUser === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
UserGitConnection::factory()->for($firstUser)->create([
|
||||
'account_login' => 'admin-user',
|
||||
'account_name' => 'Admin User',
|
||||
'api_token' => 'seeded-gitea-token',
|
||||
'base_url' => 'https://git.example.test',
|
||||
'provider' => GitProviderKey::Gitea,
|
||||
'provider_user_id' => '1001',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user