85 lines
3.1 KiB
PHP
85 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
use App\Models\Ticket;
|
|
use App\Enums\Tickets\TicketStatusEnum;
|
|
use Illuminate\Foundation\Queue\Queueable;
|
|
use App\Traits\Controllers\HasGitlabIssue;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use App\Http\Requests\Bo\ChangeTicketStatus;
|
|
|
|
class UpdateIssueLabels implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
use HasGitlabIssue;
|
|
|
|
/** @var Ticket */
|
|
protected $ticket;
|
|
|
|
/** @var requestStatus */
|
|
protected $requestStatus;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @param \App\Models\Ticket $ticket
|
|
* @param string $request
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(Ticket $ticket, string $requestStatus)
|
|
{
|
|
$this->ticket = $ticket;
|
|
$this->requestStatus = $requestStatus;
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*/
|
|
public function handle(): void
|
|
{
|
|
$oldStatus = $this->ticket->status;
|
|
$requestStatus = (int) $this->requestStatus;
|
|
$gitlabIssue = $this->getGitlabIssue($this->ticket->site->gitlab_project_id, $this->ticket->gitlab_issue);
|
|
|
|
$issueLabels = $gitlabIssue['labels'];
|
|
|
|
if ($oldStatus === TicketStatusEnum::waiting && $requestStatus !== TicketStatusEnum::waiting->value) {
|
|
$issueLabels = array_values(array_diff($issueLabels, ['g-wait']));
|
|
}
|
|
|
|
switch ($requestStatus) {
|
|
case TicketStatusEnum::takenInAccount->value:
|
|
$newLabels = ['g-to-dispatch'];
|
|
$updatedLabels = array_unique(array_merge($issueLabels, $newLabels));
|
|
|
|
$updatedIssue = $this->updateGitlabIssueLabels($gitlabIssue['project_id'], $gitlabIssue['iid'], $updatedLabels);
|
|
break;
|
|
case TicketStatusEnum::waiting->value:
|
|
$newLabels = ['g-wait'];
|
|
$updatedLabels = array_unique(array_merge($issueLabels, $newLabels));
|
|
|
|
$updatedIssue = $this->updateGitlabIssueLabels($gitlabIssue['project_id'], $gitlabIssue['iid'], $updatedLabels);
|
|
break;
|
|
case TicketStatusEnum::waitingValidation->value:
|
|
$removeLabels = ['g-to-estimate'];
|
|
$updatedLabels = array_diff($issueLabels, $removeLabels);
|
|
|
|
$updatedIssue = $this->updateGitlabIssueLabels($gitlabIssue['project_id'], $gitlabIssue['iid'], $updatedLabels);
|
|
break;
|
|
case TicketStatusEnum::recetteValidated->value:
|
|
$newLabels = ['g-re7-ok', 'to-prod'];
|
|
$updatedLabels = array_unique(array_merge($issueLabels, $newLabels));
|
|
|
|
$updatedIssue = $this->updateGitlabIssueLabels($gitlabIssue['project_id'], $gitlabIssue['iid'], $updatedLabels);
|
|
break;
|
|
case TicketStatusEnum::archived->value:
|
|
$updatedIssue = $this->closeGitlabIssue($gitlabIssue['project_id'], $gitlabIssue['iid'], $issueLabels);
|
|
break;
|
|
default:
|
|
$updatedIssue = $this->updateGitlabIssueLabels($gitlabIssue['project_id'], $gitlabIssue['iid'], $issueLabels);
|
|
break;
|
|
}
|
|
}
|
|
}
|