diff --git a/app/Http/Controllers/ApplicationController.php b/app/Http/Controllers/ApplicationController.php index f477549db..450abac73 100644 --- a/app/Http/Controllers/ApplicationController.php +++ b/app/Http/Controllers/ApplicationController.php @@ -21,7 +21,7 @@ public function configuration() if (!$application) { return redirect()->route('dashboard'); } - return view('project.application.configuration', ['application' => $application]); + return view('project.application.configuration', ['application' => $application,]); } public function deployments() { diff --git a/app/Http/Livewire/Project/Application/Source.php b/app/Http/Livewire/Project/Application/Source.php index 56d1c6e86..6876a0660 100644 --- a/app/Http/Livewire/Project/Application/Source.php +++ b/app/Http/Livewire/Project/Application/Source.php @@ -19,4 +19,13 @@ public function mount() { $this->application = Application::where('id', $this->applicationId)->first(); } + public function submit() + { + $this->validate(); + if (!$this->application->git_commit_sha) { + $this->application->git_commit_sha = 'HEAD'; + } + $this->application->save(); + $this->emit('saved', 'Application source updated!'); + } } diff --git a/app/Jobs/DeployApplicationJob.php b/app/Jobs/DeployApplicationJob.php index 08a4d5403..f4a9f27d9 100644 --- a/app/Jobs/DeployApplicationJob.php +++ b/app/Jobs/DeployApplicationJob.php @@ -430,8 +430,8 @@ private function executeNow( } private function setGitImportSettings($git_clone_command) { - if ($this->application->git_commit_sha) { - $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git checkout {$this->application->git_commit_sha}"; + if ($this->application->git_commit_sha !== 'HEAD') { + $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git -c advice.detachedHead=false checkout {$this->application->git_commit_sha} >/dev/null 2>&1"; } if ($this->application->settings->is_git_submodules_allowed) { $git_clone_command = "{$git_clone_command} && cd {$this->workdir} && git submodule update --init --recursive"; diff --git a/app/Models/Application.php b/app/Models/Application.php index 36cacf1dc..c1a0576ed 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -44,16 +44,23 @@ public function publishDirectory(): Attribute set: fn ($value) => $value ? '/' . ltrim($value, '/') : null, ); } - public function gitLocation(): Attribute + public function gitBranchLocation(): Attribute { return Attribute::make( get: function () { if (!is_null($this->source?->html_url) && !is_null($this->git_repository) && !is_null($this->git_branch)) { - if (is_null($this->git_commit_sha)) { - return "{$this->source->html_url}/{$this->git_repository}/tree/{$this->git_branch}"; - } else { - return "{$this->source->html_url}/{$this->git_repository}/tree/{$this->git_commit_sha}"; - } + return "{$this->source->html_url}/{$this->git_repository}/tree/{$this->git_branch}"; + } + } + + ); + } + public function gitCommits(): Attribute + { + return Attribute::make( + get: function () { + if (!is_null($this->source?->html_url) && !is_null($this->git_repository) && !is_null($this->git_branch)) { + return "{$this->source->html_url}/{$this->git_repository}/commits/{$this->git_branch}"; } } diff --git a/database/migrations/2023_03_27_081716_create_applications_table.php b/database/migrations/2023_03_27_081716_create_applications_table.php index 3badbe69a..3e5e4ecb0 100644 --- a/database/migrations/2023_03_27_081716_create_applications_table.php +++ b/database/migrations/2023_03_27_081716_create_applications_table.php @@ -22,7 +22,7 @@ public function up(): void $table->string('git_repository'); $table->string('git_branch'); - $table->string('git_commit_sha')->nullable(); + $table->string('git_commit_sha')->default('HEAD'); $table->string('docker_registry_image_name')->nullable(); $table->string('docker_registry_image_tag')->nullable(); diff --git a/resources/views/components/applications/navbar.blade.php b/resources/views/components/applications/navbar.blade.php index 266d8380a..e34d57df0 100644 --- a/resources/views/components/applications/navbar.blade.php +++ b/resources/views/components/applications/navbar.blade.php @@ -1,5 +1,5 @@