diff --git a/app/Models/Application.php b/app/Models/Application.php
index 0868bdf9c..af95cd4db 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -739,24 +739,20 @@ public function gitCommitLink($link): string
return "{$this->source->html_url}/{$this->git_repository}/commit/{$link}";
}
- if (str($this->git_repository)->contains('bitbucket')) {
- $git_repository = str_replace('.git', '', $this->git_repository);
- $url = Url::fromString($git_repository);
- $url = $url->withUserInfo('');
- $url = $url->withPath($url->getPath().'/commits/'.$link);
- return $url->__toString();
- }
+ $git_repository = $this->git_repository;
if (strpos($this->git_repository, 'git@') === 0) {
- $git_repository = str_replace(['git@', ':', '.git'], ['', '/', ''], $this->git_repository);
- if (data_get($this, 'source.html_url')) {
- return "{$this->source->html_url}/{$git_repository}/commit/{$link}";
- }
-
- return "{$git_repository}/commit/{$link}";
+ $git_repository = preg_replace('/^git@([^:]+):/', 'https://$1/', $git_repository);
+ } elseif (str($this->git_repository)->startsWith('ssh://')) {
+ $git_repository = 'https://'.parse_url($git_repository, PHP_URL_HOST).parse_url($git_repository, PHP_URL_PATH);
}
- return $this->git_repository;
+ $url = Url::fromString(Str::replaceEnd('.git', '', $git_repository));
+ $url = $url->withUserInfo('');
+ $commitPath = str($git_repository)->contains('bitbucket') ? 'commits' : 'commit';
+ $url = $url->withPath(Str::finish($url->getPath(), '/').$commitPath.'/'.$link);
+
+ return $url->__toString();
}
public function dockerfileLocation(): Attribute
diff --git a/resources/views/livewire/project/application/deployment/index.blade.php b/resources/views/livewire/project/application/deployment/index.blade.php
index 88301d71c..b2c2be908 100644
--- a/resources/views/livewire/project/application/deployment/index.blade.php
+++ b/resources/views/livewire/project/application/deployment/index.blade.php
@@ -213,39 +213,43 @@ class="px-2 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wider text-neut
$commitMessage = $deployment->commitMessage()
? Str::before($deployment->commitMessage(), "\n")
: null;
+ $deploymentUrl = $current_url . '/' . data_get($deployment, 'deployment_uuid');
+ $commitUrl = data_get($deployment, 'commit')
+ ? $application->gitCommitLink(data_get($deployment, 'commit'))
+ : null;
@endphp
- $selectedDeploymentUuid === data_get($deployment, 'deployment_uuid'),
])>
-
- {{ $sourceLabel }}
+
+ {{ $sourceLabel }}
@if (data_get($deployment, 'commit'))
-
+
{{ substr(data_get($deployment, 'commit'), 0, 7) }}
-
+
@if ($commitMessage)
- {{ $commitMessage }}
+ {{ $commitMessage }}
@endif
@else
-
@endif
-
+
{{ \Carbon\Carbon::parse(data_get($deployment, 'created_at'))->diffForHumans() }}
-
- {{ $duration }}
-
+
+ {{ $duration }}
+
{{ data_get($deployment, 'server_name') ?: data_get($application, 'destination.server.name', '-') }}
-
-
+
+
@endforeach
diff --git a/tests/Feature/DeploymentLogsLayoutTest.php b/tests/Feature/DeploymentLogsLayoutTest.php
index dc0b92100..be825c663 100644
--- a/tests/Feature/DeploymentLogsLayoutTest.php
+++ b/tests/Feature/DeploymentLogsLayoutTest.php
@@ -4,6 +4,7 @@
use App\Models\Application;
use App\Models\ApplicationDeploymentQueue;
use App\Models\Environment;
+use App\Models\GithubApp;
use App\Models\InstanceSettings;
use App\Models\Project;
use App\Models\Server;
@@ -214,6 +215,40 @@
->toContain(".logs-viewer-primary .logs-viewer-actions {\n width: auto;\n flex: 1 1 auto;");
});
+it('links deployment commit hashes to the source commit page', function () {
+ $githubApp = GithubApp::query()->create([
+ 'team_id' => $this->team->id,
+ 'name' => 'GitHub',
+ 'api_url' => 'https://api.github.com',
+ 'html_url' => 'https://github.com',
+ ]);
+ $this->application->update([
+ 'source_id' => $githubApp->id,
+ 'source_type' => $githubApp->getMorphClass(),
+ 'git_repository' => 'coollabsio/coolify',
+ 'git_branch' => 'main',
+ ]);
+ ApplicationDeploymentQueue::query()->create([
+ 'application_id' => $this->application->id,
+ 'deployment_uuid' => 'deploy-commit-link-test',
+ 'server_id' => $this->server->id,
+ 'status' => ApplicationDeploymentStatus::FINISHED->value,
+ 'commit' => '1234567890abcdef1234567890abcdef12345678',
+ ]);
+
+ $response = $this->get(route('project.application.deployment.index', [
+ 'project_uuid' => $this->project->uuid,
+ 'environment_uuid' => $this->environment->uuid,
+ 'application_uuid' => $this->application->uuid,
+ ]));
+
+ $response->assertSuccessful();
+ $response->assertSee(
+ 'href="https://github.com/coollabsio/coolify/commit/1234567890abcdef1234567890abcdef12345678" target="_blank" rel="noopener noreferrer"',
+ false,
+ );
+});
+
it('places cancel deployment controls inside the deployment logs toolbar', function () {
$deployment = ApplicationDeploymentQueue::create([
'application_id' => $this->application->id,
diff --git a/tests/Unit/ApplicationGitCommitLinkTest.php b/tests/Unit/ApplicationGitCommitLinkTest.php
new file mode 100644
index 000000000..e1a15e714
--- /dev/null
+++ b/tests/Unit/ApplicationGitCommitLinkTest.php
@@ -0,0 +1,28 @@
+setRelation('source', null);
+ $application->git_repository = $repository;
+
+ expect($application->gitCommitLink('1234567890abcdef'))->toBe($expected);
+})->with([
+ 'HTTPS remote' => [
+ 'https://github.com/coollabsio/coolify.git',
+ 'https://github.com/coollabsio/coolify/commit/1234567890abcdef',
+ ],
+ 'SSH remote' => [
+ 'git@github.com:coollabsio/coolify.git',
+ 'https://github.com/coollabsio/coolify/commit/1234567890abcdef',
+ ],
+ 'SSH URL' => [
+ 'ssh://git@gitlab.com/coollabsio/coolify.git',
+ 'https://gitlab.com/coollabsio/coolify/commit/1234567890abcdef',
+ ],
+ 'Bitbucket HTTPS remote' => [
+ 'https://bitbucket.org/coollabsio/coolify.git',
+ 'https://bitbucket.org/coollabsio/coolify/commits/1234567890abcdef',
+ ],
+]);