phase 4
This commit is contained in:
@@ -12,6 +12,7 @@ class EventProcessor
|
||||
public function __construct(
|
||||
private Fingerprinter $fingerprinter,
|
||||
private PayloadNormalizer $normalizer,
|
||||
private NotificationDispatcher $notificationDispatcher,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -24,7 +25,9 @@ class EventProcessor
|
||||
$fingerprint = $this->fingerprinter->compute($rawPayload);
|
||||
$now = Carbon::now();
|
||||
|
||||
$issue = $this->findOrCreateIssue($project, $data, $fingerprint, $now);
|
||||
$isNew = false;
|
||||
$isRegression = false;
|
||||
$issue = $this->findOrCreateIssue($project, $data, $fingerprint, $now, $isNew, $isRegression);
|
||||
|
||||
$event = Event::create([
|
||||
'issue_id' => $issue->id,
|
||||
@@ -48,6 +51,8 @@ class EventProcessor
|
||||
'raw_payload' => $rawPayload,
|
||||
]);
|
||||
|
||||
$this->dispatchNotifications($project, $issue, $isNew, $isRegression);
|
||||
|
||||
return $event;
|
||||
}
|
||||
|
||||
@@ -56,17 +61,23 @@ class EventProcessor
|
||||
array $data,
|
||||
string $fingerprint,
|
||||
Carbon $now,
|
||||
bool &$isNew,
|
||||
bool &$isRegression,
|
||||
): Issue {
|
||||
$issue = Issue::where('project_id', $project->id)
|
||||
->where('fingerprint', $fingerprint)
|
||||
->first();
|
||||
|
||||
if ($issue) {
|
||||
$this->updateExistingIssue($issue, $data, $now);
|
||||
$isRegression = $this->updateExistingIssue($issue, $data, $now);
|
||||
$isNew = false;
|
||||
|
||||
return $issue;
|
||||
}
|
||||
|
||||
$isNew = true;
|
||||
$isRegression = false;
|
||||
|
||||
return $this->createNewIssue($project, $data, $fingerprint, $now);
|
||||
}
|
||||
|
||||
@@ -101,7 +112,7 @@ class EventProcessor
|
||||
]);
|
||||
}
|
||||
|
||||
private function updateExistingIssue(Issue $issue, array $data, Carbon $now): void
|
||||
private function updateExistingIssue(Issue $issue, array $data, Carbon $now): bool
|
||||
{
|
||||
$wasResolved = $issue->status === 'resolved';
|
||||
|
||||
@@ -110,7 +121,11 @@ class EventProcessor
|
||||
|
||||
if ($wasResolved) {
|
||||
$issue->markRegression();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function buildTitle(?array $exception, ?string $message): string
|
||||
@@ -147,4 +162,21 @@ class EventProcessor
|
||||
|
||||
return $function ? "{$file} in {$function}" : $file;
|
||||
}
|
||||
|
||||
private function dispatchNotifications(
|
||||
Project $project,
|
||||
Issue $issue,
|
||||
bool $isNew,
|
||||
bool $isRegression,
|
||||
): void {
|
||||
if ($isNew) {
|
||||
$this->notificationDispatcher->onNewIssue($project, $issue);
|
||||
}
|
||||
|
||||
if ($isRegression) {
|
||||
$this->notificationDispatcher->onRegression($project, $issue);
|
||||
}
|
||||
|
||||
$this->notificationDispatcher->checkSpike($project, $issue);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user