fixed ( partial) for ticket level commits
This commit is contained in:
@@ -22,6 +22,7 @@ use Livewire\WithFileUploads;
|
||||
use Modules\Helpdesk\Models\CannedResponse;
|
||||
use Modules\Helpdesk\Models\ChecklistItem;
|
||||
use Modules\Helpdesk\Models\Comment;
|
||||
use Modules\Helpdesk\Models\GitCommit;
|
||||
use Modules\Helpdesk\Models\Priority;
|
||||
use Modules\Helpdesk\Models\Status;
|
||||
use Modules\Helpdesk\Models\Ticket;
|
||||
@@ -352,9 +353,10 @@ final class TicketShow extends Component
|
||||
'tags',
|
||||
'checklistItems',
|
||||
'attachments',
|
||||
'gitCommits.repository',
|
||||
]) ?? $ticket;
|
||||
|
||||
$ticket->setRelation('gitCommits', $this->ticketGitCommits($ticket));
|
||||
|
||||
$this->hydrateTicketUsers($ticket);
|
||||
|
||||
$comments = Comment::query()
|
||||
@@ -374,6 +376,63 @@ final class TicketShow extends Component
|
||||
return $ticket;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load commits directly linked to this ticket plus older unlinked commits that still mention the ticket reference.
|
||||
*
|
||||
* @return EloquentCollection<int, GitCommit>
|
||||
*/
|
||||
private function ticketGitCommits(Ticket $ticket): EloquentCollection
|
||||
{
|
||||
$referencePatterns = $this->gitCommitReferencePatterns((string) $ticket->reference);
|
||||
|
||||
return GitCommit::query()
|
||||
->with('repository')
|
||||
->where(static function ($query) use ($ticket, $referencePatterns): void {
|
||||
$query->where('ticket_id', $ticket->id);
|
||||
|
||||
foreach ($referencePatterns as $pattern) {
|
||||
$likePattern = '%' . addcslashes(Str::lower($pattern), '\\%_') . '%';
|
||||
|
||||
$query->orWhere('message', 'ILIKE', $likePattern)
|
||||
->orWhere('branch', 'ILIKE', $likePattern)
|
||||
->orWhere('url', 'ILIKE', $likePattern);
|
||||
}
|
||||
})
|
||||
->when($ticket->company_id !== null, static function ($query) use ($ticket): void {
|
||||
$query->whereHas('repository', static function ($repositoryQuery) use ($ticket): void {
|
||||
$repositoryQuery->whereNull('company_id')
|
||||
->orWhere('company_id', $ticket->company_id);
|
||||
});
|
||||
})
|
||||
->latest('committed_at')
|
||||
->latest('id')
|
||||
->get()
|
||||
->unique('id')
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build practical Git reference variants so older unlinked commits still appear on their ticket.
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private function gitCommitReferencePatterns(string $reference): array
|
||||
{
|
||||
$patterns = [Str::lower($reference)];
|
||||
|
||||
if (preg_match('/^HD-(\d{4})-(\d+)$/i', $reference, $matches) === 1) {
|
||||
$year = $matches[1];
|
||||
$number = (string) ((int) $matches[2]);
|
||||
|
||||
$patterns[] = 'hd-' . $year . '-' . $number;
|
||||
$patterns[] = 'hd ' . $year . ' ' . $number;
|
||||
$patterns[] = 'hd_' . $year . '_' . $number;
|
||||
}
|
||||
|
||||
return array_values(array_unique($patterns));
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the total logged ticket time for display.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Helpdesk\Tests\Feature;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class TicketGitCommitDisplayFilesTest extends TestCase
|
||||
{
|
||||
public function test_ticket_show_uses_safe_bound_git_commit_lookup_without_raw_like_sql(): void
|
||||
{
|
||||
$component = file_get_contents(__DIR__ . '/../../Livewire/TicketShow.php');
|
||||
|
||||
self::assertIsString($component);
|
||||
self::assertStringContainsString("setRelation('gitCommits'", $component);
|
||||
self::assertStringContainsString("orWhere('message', 'ILIKE'", $component);
|
||||
self::assertStringContainsString("orWhere('branch', 'ILIKE'", $component);
|
||||
self::assertStringContainsString("orWhere('url', 'ILIKE'", $component);
|
||||
self::assertStringNotContainsString('orWhereRaw', $component);
|
||||
self::assertStringNotContainsString('lower(message) like', strtolower($component));
|
||||
}
|
||||
|
||||
public function test_ticket_show_preserves_livewire_safe_expandable_sidebar_cards(): void
|
||||
{
|
||||
$view = file_get_contents(__DIR__ . '/../../Resources/views/livewire/ticket-show.blade.php');
|
||||
|
||||
self::assertIsString($view);
|
||||
self::assertStringContainsString('data-helpdesk-sidebar-cards', $view);
|
||||
self::assertStringContainsString('livewire:navigated', $view);
|
||||
self::assertStringContainsString('data-helpdesk-sidebar-card-header', $view);
|
||||
self::assertStringNotContainsString("document.createElement('details')", $view);
|
||||
}
|
||||
}
|
||||
@@ -503,3 +503,14 @@
|
||||
- Moved the ticket show inline sidebar styles inside the Livewire root container to preserve stable Livewire component markup.
|
||||
- Added file-level regression coverage for Livewire-safe sidebar card expansion behaviour.
|
||||
- Preserved append-only changelog history.
|
||||
|
||||
- version: 1.10.22
|
||||
date: 2026-06-24
|
||||
type: bugfix
|
||||
summary: Safely show Helpdesk Git commits on ticket display without breaking sidebar cards.
|
||||
changes:
|
||||
- Rebuilt the ticket Git commits display fix on top of the working expandable-card ticket view baseline.
|
||||
- Replaced raw lower LIKE SQL with bound PostgreSQL ILIKE query-builder clauses so fallback commit matching no longer raises HY093 binding errors.
|
||||
- Kept directly linked commits visible while also finding older unlinked commits that mention the ticket reference in commit message, branch or URL.
|
||||
- Added file-level regression coverage for safe Git commit lookup and Livewire-safe expandable sidebar cards.
|
||||
- Preserved append-only changelog history.
|
||||
|
||||
@@ -23,5 +23,5 @@
|
||||
"Modules\\Helpdesk\\Providers\\HelpdeskServiceProvider"
|
||||
],
|
||||
"files": [],
|
||||
"version": "1.10.21"
|
||||
"version": "1.10.22"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user