Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Jan 10, 2025
1 parent de7f7e8 commit fd2a2a6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
16 changes: 8 additions & 8 deletions src/GithubIssueFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function formatBatch(array $records): array
private function generateSignature(LogRecord $record, ?Throwable $exception): string
{
if (! $exception) {
return md5($record->message.json_encode($record->context));
return md5($record->message . json_encode($record->context));
}

$trace = $exception->getTrace();
Expand All @@ -64,7 +64,7 @@ private function generateSignature(LogRecord $record, ?Throwable $exception): st
$exception::class,
$exception->getFile(),
$exception->getLine(),
$firstFrame ? ($firstFrame['file'] ?? '').':'.($firstFrame['line'] ?? '') : '',
$firstFrame ? ($firstFrame['file'] ?? '') . ':' . ($firstFrame['line'] ?? '') : '',
]));
}

Expand Down Expand Up @@ -110,7 +110,7 @@ private function formatTitle(LogRecord $record, ?Throwable $exception = null): s
private function formatContent(LogRecord $record, ?Throwable $exception): string
{
return Str::of('')
->when($record->message, fn ($str, $message) => $str->append("**Message:**\n{$message}\n\n"))
->when($record->message, fn($str, $message) => $str->append("**Message:**\n{$message}\n\n"))
->when(
$exception,
function (Stringable $str, Throwable $exception) {
Expand All @@ -120,8 +120,8 @@ function (Stringable $str, Throwable $exception) {
);
}
)
->when(! $exception && ! empty($record->context), fn ($str, $context) => $str->append("**Context:**\n```json\n{$context}\n```\n\n"))
->when(! empty($record->extra), fn ($str, $extra) => $str->append("**Extra Data:**\n```json\n{$extra}\n```\n"))
->when(!$exception && !empty($record->context), fn($str, $context) => $str->append("**Context:**\n```json\n" . json_encode($record->context, JSON_PRETTY_PRINT) . "\n```\n\n"))
->when(!empty($record->extra), fn($str, $extra) => $str->append("**Extra Data:**\n```json\n" . json_encode($record->extra, JSON_PRETTY_PRINT) . "\n```\n"))
->toString();
}

Expand All @@ -141,7 +141,7 @@ private function formatBody(LogRecord $record, string $signature, ?Throwable $ex
private function cleanStackTrace(string $stackTrace): string
{
return collect(explode("\n", $stackTrace))
->filter(fn ($line) => ! empty(trim($line)))
->filter(fn($line) => ! empty(trim($line)))
->map(function ($line) {
if (trim($line) === '"}') {
return '';
Expand Down Expand Up @@ -217,8 +217,8 @@ private function formatExceptionDetails(Throwable $exception): array

return [
'message' => $exception->getMessage(),
'stack_trace' => $header."\n[stacktrace]\n".$this->cleanStackTrace($exception->getTraceAsString()),
'full_stack_trace' => $header."\n[stacktrace]\n".$exception->getTraceAsString(),
'stack_trace' => $header . "\n[stacktrace]\n" . $this->cleanStackTrace($exception->getTraceAsString()),
'full_stack_trace' => $header . "\n[stacktrace]\n" . $exception->getTraceAsString(),
];
}

Expand Down
4 changes: 2 additions & 2 deletions tests/GithubIssueFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
$formatted = $formatter->format($record);

expect($formatted->body)
->toContain('"user_id":123')
->toContain('"action":"login"');
->toContain('"user_id": 123')
->toContain('"action": "login"');
});

test('it generates consistent signatures for similar errors', function () {
Expand Down
4 changes: 2 additions & 2 deletions tests/GithubIssueLoggerHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ function createFormattedRecord(GithubIssueLoggerHandler $handler, string $messag

Http::assertSent(function ($request) {
return $request->url() === 'https://api.github.com/repos/test/repo/issues' &&
str_contains($request['body'], '"server":"production"') &&
str_contains($request['body'], '"user_id":123');
str_contains($request['body'], '"server": "production"') &&
str_contains($request['body'], '"user_id": 123');
});
});

Expand Down

0 comments on commit fd2a2a6

Please sign in to comment.