new deployer command

This commit is contained in:
Mark Gregory
2026-09-16 13:22:16 +01:00
parent fac5df8cc3
commit 3410ab85fe
15 changed files with 26429 additions and 441 deletions
+17 -20
View File
@@ -45,16 +45,13 @@ final class AttachmentService
$size = (int) Storage::disk($disk)->size($path);
}
Attachment::query()->create($this->attachmentAttributes(
ticket: $ticket,
comment: $comment,
userId: $userId,
disk: $disk,
path: $path,
originalName: $originalName,
mimeType: $mimeType,
size: $size,
));
Attachment::query()->create($this->attachmentAttributes($ticket, $comment, $userId, [
'disk' => $disk,
'path' => $path,
'original_name' => $originalName,
'mime_type' => $mimeType,
'size' => $size,
]));
}
}
@@ -72,29 +69,29 @@ final class AttachmentService
*
* @return array<string, mixed>
*/
private function attachmentAttributes(Ticket $ticket, ?Comment $comment, int $userId, string $disk, string $path, string $originalName, string $mimeType, int $size): array
private function attachmentAttributes(Ticket $ticket, ?Comment $comment, int $userId, array $file): array
{
$attributes = [
'ticket_id' => $ticket->id,
'comment_id' => $comment?->id,
'user_id' => $userId,
'disk' => $disk,
'path' => $path,
'original_name' => $originalName,
'mime_type' => $mimeType,
'size' => $size,
'disk' => $file['disk'],
'path' => $file['path'],
'original_name' => $file['original_name'],
'mime_type' => $file['mime_type'],
'size' => $file['size'],
];
if (Schema::hasColumn('helpdesk_attachments', 'extension')) {
$attributes['extension'] = strtolower((string) pathinfo($originalName, PATHINFO_EXTENSION));
$attributes['extension'] = strtolower((string) pathinfo($file['original_name'], PATHINFO_EXTENSION));
}
if (Schema::hasColumn('helpdesk_attachments', 'category')) {
$attributes['category'] = $this->categoryFor($originalName, $mimeType);
$attributes['category'] = $this->categoryFor($file['original_name'], $file['mime_type']);
}
if (Schema::hasColumn('helpdesk_attachments', 'checksum_sha256') && Storage::disk($disk)->exists($path)) {
$stream = Storage::disk($disk)->readStream($path);
if (Schema::hasColumn('helpdesk_attachments', 'checksum_sha256') && Storage::disk($file['disk'])->exists($file['path'])) {
$stream = Storage::disk($file['disk'])->readStream($file['path']);
if (is_resource($stream)) {
$context = hash_init('sha256');
@@ -23,6 +23,8 @@ use Throwable;
final class GitWebhookIngestionService
{
private const PUSH_HOOK = 'push hook';
/**
* Matches the generated Helpdesk reference format, for example HD-2026-00042.
*/
@@ -173,10 +175,10 @@ final class GitWebhookIngestionService
return match ($normalisedProvider) {
'github' => in_array($normalisedEvent, ['push', ''], true),
'gitlab' => in_array($normalisedEvent, ['push hook', 'push', ''], true),
'gitea' => in_array($normalisedEvent, ['push', 'push hook', ''], true),
'gitlab' => in_array($normalisedEvent, [self::PUSH_HOOK, 'push', ''], true),
'gitea' => in_array($normalisedEvent, ['push', self::PUSH_HOOK, ''], true),
'bitbucket' => in_array($normalisedEvent, ['repo push', 'push', ''], true),
default => in_array($normalisedEvent, ['push', 'repo push', 'push hook', ''], true),
default => in_array($normalisedEvent, ['push', 'repo push', self::PUSH_HOOK, ''], true),
};
}
@@ -214,23 +216,14 @@ final class GitWebhookIngestionService
{
$commits = $payload['commits'] ?? null;
if (is_array($commits) && $commits !== []) {
return array_values(array_filter($commits, static fn (mixed $commit): bool => is_array($commit)));
if (! is_array($commits) || $commits === []) {
$headCommit = $payload['head_commit'] ?? null;
$commits = is_array($headCommit) ? [$headCommit] : Arr::get($payload, 'push.changes.0.commits', []);
}
$headCommit = $payload['head_commit'] ?? null;
if (is_array($headCommit)) {
return [$headCommit];
}
$bitbucketCommits = Arr::get($payload, 'push.changes.0.commits', []);
if (is_array($bitbucketCommits)) {
return array_values(array_filter($bitbucketCommits, static fn (mixed $commit): bool => is_array($commit)));
}
return [];
return is_array($commits)
? array_values(array_filter($commits, static fn (mixed $commit): bool => is_array($commit)))
: [];
}
/**
+2 -1
View File
@@ -190,7 +190,8 @@ final class TicketService
];
if (Schema::hasColumn('helpdesk_comments', 'subject')) {
$payload['subject'] = trim((string) ($subject ?: ($parentId === null ? 'Response' : 'RE: Response')));
$defaultSubject = $parentId === null ? 'Response' : 'RE: Response';
$payload['subject'] = trim((string) ($subject ?: $defaultSubject));
}
return $payload;
@@ -34,7 +34,7 @@ final class WorkflowNotificationService
$recipient = $this->recipient($template->to_role, $ticket, $actor);
if ($recipient === null || blank($recipient->email ?? null)) {
$this->log($template, $ticket, $event, null, 'skipped', 'No recipient email was available.');
$this->log($template, $ticket, $event, ['recipient' => null, 'status' => 'skipped', 'error' => 'No recipient email was available.']);
return;
}
@@ -56,10 +56,10 @@ final class WorkflowNotificationService
}
});
$this->log($template, $ticket, $event, (string) $recipient->email, 'sent', null, $subject, $trackingToken);
$this->log($template, $ticket, $event, ['recipient' => (string) $recipient->email, 'status' => 'sent', 'subject' => $subject, 'tracking_token' => $trackingToken]);
} catch (Throwable $exception) {
Log::warning('Helpdesk workflow email failed.', ['event' => $event, 'ticket_id' => $ticket->id, 'error' => $exception->getMessage()]);
$this->log($template, $ticket, $event, (string) $recipient->email, 'failed', $exception->getMessage(), $subject);
$this->log($template, $ticket, $event, ['recipient' => (string) $recipient->email, 'status' => 'failed', 'error' => $exception->getMessage(), 'subject' => $subject]);
}
});
}
@@ -157,17 +157,18 @@ final class WorkflowNotificationService
return '<img src="' . e($url) . '" width="1" height="1" alt="" style="display:none" />';
}
private function log(WorkflowTemplate $template, Ticket $ticket, string $event, ?string $recipient, string $status, ?string $error = null, ?string $subject = null, ?string $trackingToken = null): void
/** @param array{recipient:?string,status:string,error?:?string,subject?:?string,tracking_token?:?string} $details */
private function log(WorkflowTemplate $template, Ticket $ticket, string $event, array $details): void
{
WorkflowLog::query()->create([
'template_id' => $template->id,
'ticket_id' => $ticket->id,
'event' => $event,
'recipient' => $recipient,
'subject' => $subject,
'status' => $status,
'tracking_token' => $trackingToken,
'error' => $error,
'recipient' => $details['recipient'],
'subject' => $details['subject'] ?? null,
'status' => $details['status'],
'tracking_token' => $details['tracking_token'] ?? null,
'error' => $details['error'] ?? null,
]);
}
}