Refactor gitCommitLink method to handle different git repository formats
This commit is contained in:
		@@ -189,6 +189,17 @@ class Application extends BaseModel
 | 
			
		||||
            }
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
    public function gitCommitLink($link): string
 | 
			
		||||
    {
 | 
			
		||||
        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}/commit/{$link}";
 | 
			
		||||
        }
 | 
			
		||||
        if (strpos($this->git_repository, 'git@') === 0) {
 | 
			
		||||
            $git_repository = str_replace(['git@', ':', '.git'], ['', '/', ''], $this->git_repository);
 | 
			
		||||
            return "https://{$git_repository}/commit/{$link}";
 | 
			
		||||
        }
 | 
			
		||||
        return $this->git_repository;
 | 
			
		||||
    }
 | 
			
		||||
    public function dockerfileLocation(): Attribute
 | 
			
		||||
    {
 | 
			
		||||
        return Attribute::make(
 | 
			
		||||
 
 | 
			
		||||
@@ -27,18 +27,15 @@
 | 
			
		||||
            </form>
 | 
			
		||||
        @endif
 | 
			
		||||
        @forelse ($deployments as $deployment)
 | 
			
		||||
            <a @class([
 | 
			
		||||
                'dark:bg-coolgray-100 p-2 border-l border-dashed transition-colors hover:no-underline box-without-bg-without-border bg-white flex-col',
 | 
			
		||||
                'dark:hover:bg-coolgray-200' =>
 | 
			
		||||
                    data_get($deployment, 'status') === 'queued',
 | 
			
		||||
                'border-warning hover:bg-warning hover:text-black' =>
 | 
			
		||||
            <div @class([
 | 
			
		||||
                'dark:bg-coolgray-100 p-2 border-l border-dashed transition-colors hover:no-underline box-without-bg-without-border bg-white flex-col cursor-pointer dark:hover:text-neutral-400 dark:hover:bg-coolgray-200',
 | 
			
		||||
                'border-warning' =>
 | 
			
		||||
                    data_get($deployment, 'status') === 'in_progress' ||
 | 
			
		||||
                    data_get($deployment, 'status') === 'cancelled-by-user',
 | 
			
		||||
                'border-error dark:hover:bg-error hover:bg-neutral-200' =>
 | 
			
		||||
                    data_get($deployment, 'status') === 'failed',
 | 
			
		||||
                'border-success dark:hover:bg-success hover:bg-neutral-200' =>
 | 
			
		||||
                    data_get($deployment, 'status') === 'finished',
 | 
			
		||||
            ]) href="{{ $current_url . '/' . data_get($deployment, 'deployment_uuid') }}">
 | 
			
		||||
                'border-error' => data_get($deployment, 'status') === 'failed',
 | 
			
		||||
                'border-success' => data_get($deployment, 'status') === 'finished',
 | 
			
		||||
            ])
 | 
			
		||||
                x-on:click.stop="goto('{{ $current_url . '/' . data_get($deployment, 'deployment_uuid') }}')">
 | 
			
		||||
                <div class="flex flex-col justify-start">
 | 
			
		||||
                    <div class="flex gap-1">
 | 
			
		||||
                        {{ $deployment->created_at }} UTC
 | 
			
		||||
@@ -64,8 +61,17 @@
 | 
			
		||||
                            @endif
 | 
			
		||||
                        </div>
 | 
			
		||||
                    @else
 | 
			
		||||
                        <div class="flex gap-1">
 | 
			
		||||
                            Manual
 | 
			
		||||
                        <div class="flex items-center gap-1">
 | 
			
		||||
                            Manual @if (data_get($deployment, 'rollback') === true)
 | 
			
		||||
                                <div class="text-xs">rolled back to </div>
 | 
			
		||||
                            @endif
 | 
			
		||||
                            @if (data_get($deployment, 'commit'))
 | 
			
		||||
                                <div class="dark:hover:text-white"
 | 
			
		||||
                                x-on:click.stop="goto('{{ $application->gitCommitLink(data_get($deployment, 'commit')) }}')">
 | 
			
		||||
                                    <div class="text-xs underline">
 | 
			
		||||
                                        ({{ data_get($deployment, 'commit') }})</div>
 | 
			
		||||
                                </div>
 | 
			
		||||
                            @endif
 | 
			
		||||
                        </div>
 | 
			
		||||
                    @endif
 | 
			
		||||
                    @if (data_get($deployment, 'server_name'))
 | 
			
		||||
@@ -85,15 +91,19 @@
 | 
			
		||||
                        <span class="font-bold" x-text="measure_finished_time()">0s</span>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </div>
 | 
			
		||||
            </a>
 | 
			
		||||
            </div>
 | 
			
		||||
        @empty
 | 
			
		||||
            <div class="">No deployments found</div>
 | 
			
		||||
        @endforelse
 | 
			
		||||
 | 
			
		||||
        @if ($deployments_count > 0)
 | 
			
		||||
            <script src="https://cdn.jsdelivr.net/npm/dayjs@1/dayjs.min.js"></script>
 | 
			
		||||
            <script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/utc.js"></script>
 | 
			
		||||
            <script src="https://cdn.jsdelivr.net/npm/dayjs@1/plugin/relativeTime.js"></script>
 | 
			
		||||
            <script>
 | 
			
		||||
                function goto(url) {
 | 
			
		||||
                    window.location.href = url;
 | 
			
		||||
                };
 | 
			
		||||
                document.addEventListener('alpine:init', () => {
 | 
			
		||||
                    let timers = {};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user