codex ticket rework
This commit is contained in:
@@ -8,26 +8,24 @@ class InitializeProjectTicketMetadata
|
||||
{
|
||||
public function handle(Project $project): void
|
||||
{
|
||||
$project->ticketTypes()->create(
|
||||
[
|
||||
if (! $project->ticketTypes()->exists()) {
|
||||
$project->ticketTypes()->create([
|
||||
'name' => 'Task',
|
||||
'position' => 1,
|
||||
],
|
||||
);
|
||||
]);
|
||||
|
||||
$project->ticketTypes()->create(
|
||||
[
|
||||
$project->ticketTypes()->create([
|
||||
'name' => 'Release',
|
||||
'is_parent' => true,
|
||||
'position' => 2,
|
||||
],
|
||||
);
|
||||
]);
|
||||
}
|
||||
|
||||
$project->ticketPriorities()->create(
|
||||
[
|
||||
if (! $project->ticketPriorities()->exists()) {
|
||||
$project->ticketPriorities()->create([
|
||||
'name' => 'Medium',
|
||||
'position' => 1,
|
||||
]
|
||||
);
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Actions\Tickets;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\User;
|
||||
use Arr;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateProjectTicket
|
||||
@@ -17,7 +17,9 @@ class CreateProjectTicket
|
||||
/**
|
||||
* @param array{
|
||||
* acceptance_criteria: string|null,
|
||||
* assignee_user_id?: int|null,
|
||||
* description: string|null,
|
||||
* story_points?: int|null,
|
||||
* ticket_priority_id: int,
|
||||
* ticket_type_id: int,
|
||||
* title: string
|
||||
@@ -31,15 +33,17 @@ class CreateProjectTicket
|
||||
->max('sequence_number') + 1;
|
||||
|
||||
$ticket = Ticket::query()->create([
|
||||
'acceptance_criteria' => $attributes['acceptance_criteria'],
|
||||
'acceptance_criteria' => Arr::get($attributes, 'acceptance_criteria'),
|
||||
'assignee_user_id' => Arr::get($attributes, 'assignee_user_id'),
|
||||
'author_user_id' => $actor?->id,
|
||||
'board_column_id' => null,
|
||||
'description' => $attributes['description'],
|
||||
'description' => Arr::get($attributes, 'description'),
|
||||
'project_id' => $project->id,
|
||||
'sequence_number' => $nextSequenceNumber,
|
||||
'ticket_key' => "{$project->key}-{$nextSequenceNumber}",
|
||||
'ticket_priority_id' => $attributes['ticket_priority_id'],
|
||||
'ticket_type_id' => $attributes['ticket_type_id'],
|
||||
'title' => $attributes['title'],
|
||||
'ticket_priority_id' => Arr::get($attributes, 'ticket_priority_id'),
|
||||
'ticket_type_id' => Arr::get($attributes, 'ticket_type_id'),
|
||||
'title' => Arr::get($attributes, 'title'),
|
||||
'story_points' => Arr::get($attributes, 'story_points'),
|
||||
]);
|
||||
|
||||
|
||||
@@ -18,9 +18,12 @@ class UpdateProjectTicket
|
||||
/**
|
||||
* @param array{
|
||||
* acceptance_criteria: string|null,
|
||||
* assignee_user_id: int|null,
|
||||
* author_user_id: int|null,
|
||||
* blocked_comment: string|null,
|
||||
* description: string|null,
|
||||
* is_blocked: bool,
|
||||
* story_points: int|null,
|
||||
* ticket_priority_id: int,
|
||||
* ticket_type_id: int,
|
||||
* parent_ticket_id: int|null,
|
||||
@@ -44,6 +47,8 @@ class UpdateProjectTicket
|
||||
}
|
||||
|
||||
$ticket->loadMissing([
|
||||
'assignee',
|
||||
'author',
|
||||
'fieldValues.ticketFieldDefinition',
|
||||
'fieldValues.userValue',
|
||||
'parentTicket',
|
||||
@@ -103,6 +108,14 @@ class UpdateProjectTicket
|
||||
$ticket->blocked_comment,
|
||||
$ticketAttributes['blocked_comment'],
|
||||
);
|
||||
$this->trackNumberChange(
|
||||
$changes,
|
||||
$summaryLabels,
|
||||
'story_points',
|
||||
'story points',
|
||||
$ticket->story_points,
|
||||
$ticketAttributes['story_points'],
|
||||
);
|
||||
|
||||
if ($ticket->ticket_type_id !== $ticketAttributes['ticket_type_id']) {
|
||||
$changes['ticket_type'] = [
|
||||
@@ -140,6 +153,26 @@ class UpdateProjectTicket
|
||||
$summaryLabels[] = 'parent ticket';
|
||||
}
|
||||
|
||||
if ($ticket->assignee_user_id !== $ticketAttributes['assignee_user_id']) {
|
||||
$changes['assignee'] = [
|
||||
'from' => $ticket->assignee?->name,
|
||||
'to' => $ticketAttributes['assignee_user_id'] === null
|
||||
? null
|
||||
: User::query()->find($ticketAttributes['assignee_user_id'])?->name,
|
||||
];
|
||||
$summaryLabels[] = 'assignee';
|
||||
}
|
||||
|
||||
if ($ticket->author_user_id !== $ticketAttributes['author_user_id']) {
|
||||
$changes['author'] = [
|
||||
'from' => $ticket->author?->name,
|
||||
'to' => $ticketAttributes['author_user_id'] === null
|
||||
? null
|
||||
: User::query()->find($ticketAttributes['author_user_id'])?->name,
|
||||
];
|
||||
$summaryLabels[] = 'author';
|
||||
}
|
||||
|
||||
$ticket->fill($ticketAttributes);
|
||||
|
||||
if ($ticket->isDirty()) {
|
||||
@@ -217,6 +250,29 @@ class UpdateProjectTicket
|
||||
$summaryLabels[] = $summaryLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $changes
|
||||
* @param array<int, string> $summaryLabels
|
||||
*/
|
||||
private function trackNumberChange(
|
||||
array &$changes,
|
||||
array &$summaryLabels,
|
||||
string $changeKey,
|
||||
string $summaryLabel,
|
||||
?int $currentValue,
|
||||
?int $newValue,
|
||||
): void {
|
||||
if ($currentValue === $newValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
$changes[$changeKey] = [
|
||||
'from' => $currentValue,
|
||||
'to' => $newValue,
|
||||
];
|
||||
$summaryLabels[] = $summaryLabel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $changes
|
||||
* @param array{value_user_id?: int|string|null} $fieldValueAttribute
|
||||
|
||||
Reference in New Issue
Block a user