From 733f6ca2ebc2d199886559224948b722f7afb0ea Mon Sep 17 00:00:00 2001 From: Bozhidar Date: Tue, 10 Sep 2024 18:14:49 +0300 Subject: [PATCH] update --- .../Resources/GitRepositoryResource.php | 116 ++++++++++++++++++ .../Pages/CreateGitRepository.php | 19 +++ .../Pages/EditGitRepository.php | 19 +++ .../Pages/ListGitRepositories.php | 19 +++ web/app/GitClient.php | 100 +++++++++++++++ web/app/Models/GitRepository.php | 24 ++++ ...0_142433_create_git_repositories_table.php | 43 +++++++ web/resources/phyre-customer-svg/git.svg | 3 + web/resources/phyre-svg/git.svg | 3 + 9 files changed, 346 insertions(+) create mode 100644 web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php create mode 100644 web/Modules/Customer/App/Filament/Resources/GitRepositoryResource/Pages/CreateGitRepository.php create mode 100644 web/Modules/Customer/App/Filament/Resources/GitRepositoryResource/Pages/EditGitRepository.php create mode 100644 web/Modules/Customer/App/Filament/Resources/GitRepositoryResource/Pages/ListGitRepositories.php create mode 100644 web/app/GitClient.php create mode 100644 web/app/Models/GitRepository.php create mode 100644 web/database/migrations/2024_09_10_142433_create_git_repositories_table.php create mode 100644 web/resources/phyre-customer-svg/git.svg create mode 100644 web/resources/phyre-svg/git.svg diff --git a/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php new file mode 100644 index 0000000..3791af2 --- /dev/null +++ b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource.php @@ -0,0 +1,116 @@ +schema([ + + Forms\Components\TextInput::make('url') + ->label('URL') + ->required() + ->columnSpanFull() + ->live() + ->afterStateUpdated(function ($state, Forms\Set $set) use (&$branches, &$tags) { + $state = trim($state); + + $repoDetails = GitClient::getRepoDetailsByUrl($state); + if ($repoDetails['name']) { + $set('name', $repoDetails['owner'] .'/'. $repoDetails['name']); + $branches = $repoDetails['branches']; + $tags = $repoDetails['tags']; + } + }) + ->placeholder('Enter the URL of the repository'), + + + Forms\Components\TextInput::make('name') + ->label('Name') + ->required() + ->columnSpanFull() + ->placeholder('Enter the name of the repository'), + + Forms\Components\Select::make('branch') + ->label('Branch') + ->required() + ->options($branches) + ->live() + ->columnSpanFull() + ->placeholder('Enter the branch of the repository'), + + Forms\Components\Select::make('tag') + ->label('Tag') + ->live() + ->options($tags) + ->columnSpanFull() + ->placeholder('Enter the tag of the repository'), + + Forms\Components\TextInput::make('dir') + ->label('Directory') + ->columnSpanFull() + ->required() + ->placeholder('Enter the directory of the repository'), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + // + ]) + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + ]), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListGitRepositories::route('/'), + 'create' => Pages\CreateGitRepository::route('/create'), + 'edit' => Pages\EditGitRepository::route('/{record}/edit'), + ]; + } +} diff --git a/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource/Pages/CreateGitRepository.php b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource/Pages/CreateGitRepository.php new file mode 100644 index 0000000..7051436 --- /dev/null +++ b/web/Modules/Customer/App/Filament/Resources/GitRepositoryResource/Pages/CreateGitRepository.php @@ -0,0 +1,19 @@ + $name, + 'owner' => $owner, + 'provider' => $provider + ]; + + } + + public static function getRepoDetailsByUrl($url) + { + + shell_exec('GIT_TERMINAL_PROMPT=0'); + $outputBranches = shell_exec('git ls-remote --heads '.$url); + $outputTags = shell_exec('git ls-remote --tags '.$url); + + $branches = []; + $tags = []; + + $gitUrl = self::parseGitUrl($url); + + foreach (explode("\n", $outputBranches) as $line) { + if (empty($line)) { + continue; + } + $parts = explode("\t", $line); + $branch = str_replace('refs/heads/', '', $parts[1]); + $branches[$branch] = $branch; + } + + foreach (explode("\n", $outputTags) as $line) { + if (empty($line)) { + continue; + } + $parts = explode("\t", $line); + $tag = str_replace('refs/tags/', '', $parts[1]); + $tags[$tag] = $tag; + } + + $output = [ + 'branches' => $branches, + 'tags' => $tags, + 'name' => $gitUrl['name'], + 'owner' => $gitUrl['owner'], + 'provider' => $gitUrl['provider'] + ]; + + return $output; + } + +} diff --git a/web/app/Models/GitRepository.php b/web/app/Models/GitRepository.php new file mode 100644 index 0000000..f2e5f3e --- /dev/null +++ b/web/app/Models/GitRepository.php @@ -0,0 +1,24 @@ +id(); + + $table->string('name'); + $table->string('url'); + $table->string('branch'); + $table->string('last_commit_hash')->nullable(); + $table->string('last_commit_message')->nullable(); + $table->timestamp('last_commit_date')->nullable(); + + $table->string('status')->nullable(); + $table->string('status_message')->nullable(); + + $table->string('dir')->nullable(); + + $table->unsignedBigInteger('domain_id'); + + + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('git_repositories'); + } +}; diff --git a/web/resources/phyre-customer-svg/git.svg b/web/resources/phyre-customer-svg/git.svg new file mode 100644 index 0000000..356184d --- /dev/null +++ b/web/resources/phyre-customer-svg/git.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/web/resources/phyre-svg/git.svg b/web/resources/phyre-svg/git.svg new file mode 100644 index 0000000..356184d --- /dev/null +++ b/web/resources/phyre-svg/git.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file