fix(deployments): restore commit links in deployment logs (#11495)

This commit is contained in:
Andras Bacsai 2026-08-25 12:12:12 +02:00 committed by GitHub
parent cfca155890
commit abeb839a69
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 92 additions and 29 deletions

View file

@ -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

View file

@ -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
<a wire:key="deployment-{{ data_get($deployment, 'deployment_uuid') }}"
href="{{ $current_url . '/' . data_get($deployment, 'deployment_uuid') }}"
{{ wireNavigate() }}
<div wire:key="deployment-{{ data_get($deployment, 'deployment_uuid') }}"
@class([
'data-table-row deployment-table-grid border-b border-neutral-200 text-[13px] text-neutral-600 dark:border-white/[0.08] dark:text-fg-dim',
'data-table-row-active' => $selectedDeploymentUuid === data_get($deployment, 'deployment_uuid'),
])>
<span><x-status-badge :status="$statusLabel" :type="$statusType" /></span>
<span>{{ $sourceLabel }}</span>
<a href="{{ $deploymentUrl }}" {{ wireNavigate() }}><x-status-badge :status="$statusLabel" :type="$statusType" /></a>
<a href="{{ $deploymentUrl }}" {{ wireNavigate() }}>{{ $sourceLabel }}</a>
<span class="min-w-0">
@if (data_get($deployment, 'commit'))
<span class="flex min-w-0 items-center gap-2">
<span class="shrink-0 font-mono text-xs text-neutral-950 dark:text-fg">
<a href="{{ $commitUrl }}" target="_blank" rel="noopener noreferrer"
class="shrink-0 font-mono text-xs text-neutral-950 underline decoration-neutral-400 underline-offset-2 dark:text-fg dark:decoration-neutral-600">
{{ substr(data_get($deployment, 'commit'), 0, 7) }}
</span>
</a>
@if ($commitMessage)
<span class="truncate text-neutral-500 dark:text-fg-faint"
title="{{ $commitMessage }}">{{ $commitMessage }}</span>
<a href="{{ $deploymentUrl }}" {{ wireNavigate() }}
class="truncate text-neutral-500 dark:text-fg-faint"
title="{{ $commitMessage }}">{{ $commitMessage }}</a>
@endif
</span>
@else
<span class="text-neutral-400 dark:text-fg-faint">-</span>
@endif
</span>
<span title="{{ formatDateInServerTimezone(data_get($deployment, 'created_at'), data_get($application, 'destination.server')) }}">
<a href="{{ $deploymentUrl }}" {{ wireNavigate() }} title="{{ formatDateInServerTimezone(data_get($deployment, 'created_at'), data_get($application, 'destination.server')) }}">
{{ \Carbon\Carbon::parse(data_get($deployment, 'created_at'))->diffForHumans() }}
</span>
<span class="tabular-nums">{{ $duration }}</span>
<span class="truncate">
</a>
<a href="{{ $deploymentUrl }}" {{ wireNavigate() }} class="tabular-nums">{{ $duration }}</a>
<a href="{{ $deploymentUrl }}" {{ wireNavigate() }} class="truncate">
{{ data_get($deployment, 'server_name') ?: data_get($application, 'destination.server.name', '-') }}
</span>
</a>
</a>
</div>
@endforeach
</div>

View file

@ -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,

View file

@ -0,0 +1,28 @@
<?php
use App\Models\Application;
it('generates commit links for direct repository remotes', function (string $repository, string $expected) {
$application = new Application;
$application->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',
],
]);