Skip to content

Commit 9039b23

Browse files
committed
Issue bot: append 🔧 to messages of fixable errors
Matches the table output, so an error becoming fixable or no longer fixable shows up in the diff. Amp-Thread-ID: https://ampcode.com/threads/T-01a198ef-d81e-7532-81f4-438bae7a4db3
1 parent 434d72b commit 9039b23

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎issue-bot/src/Console/RunCommand.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public static function extractErrors(array $json, string $hash): array
262262
if (strpos($messageText, 'Internal error') !== false) {
263263
throw new Exception(sprintf('While analysing %s: %s', $hash, $messageText));
264264
}
265-
$errors[] = new PlaygroundError($message['line'] ?? -1, $messageText, $message['identifier'] ?? null);
265+
$errors[] = new PlaygroundError($message['line'] ?? -1, $messageText, $message['identifier'] ?? null, $message['fixable'] ?? false);
266266
}
267267
}
268268

‎issue-bot/src/Playground/PlaygroundClient.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getResult(string $hash): PlaygroundResult
2525

2626
$versionedErrors = [];
2727
foreach ($json['versionedErrors'] as ['phpVersion' => $phpVersion, 'errors' => $errors]) {
28-
$versionedErrors[(int) $phpVersion] = array_map(static fn (array $error) => new PlaygroundError($error['line'] ?? -1, $error['message'], $error['identifier'] ?? null), array_values($errors));
28+
$versionedErrors[(int) $phpVersion] = array_map(static fn (array $error) => new PlaygroundError($error['line'] ?? -1, $error['message'], $error['identifier'] ?? null, $error['fixable'] ?? false), array_values($errors));
2929
}
3030

3131
$options = [];

‎issue-bot/src/Playground/PlaygroundError.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
class PlaygroundError
66
{
77

8-
public function __construct(private int $line, private string $message, private ?string $identifier)
8+
public function __construct(private int $line, private string $message, private ?string $identifier, private bool $fixable = false)
99
{
1010
}
1111

@@ -16,7 +16,8 @@ public function getLine(): int
1616

1717
public function getMessage(): string
1818
{
19-
return $this->message;
19+
// shown like in the table output, so that an error becoming fixable shows up in the diff
20+
return $this->fixable ? $this->message . ' 🔧' : $this->message;
2021
}
2122

2223
public function getIdentifier(): ?string

‎issue-bot/tests/Console/RunCommandTest.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function testExtractFileErrors(): void
1919
'errors' => 2,
2020
'messages' => [
2121
['message' => 'Dumped type: int', 'line' => 5, 'identifier' => 'phpstan.dumpType'],
22-
['message' => 'Something else', 'line' => 7, 'identifier' => 'foo.bar'],
22+
['message' => 'Something else', 'line' => 7, 'identifier' => 'foo.bar', 'fixable' => true],
2323
],
2424
],
2525
],
@@ -33,6 +33,7 @@ public function testExtractFileErrors(): void
3333
self::assertSame('Dumped type: int', $errors[0]->getMessage());
3434
self::assertSame('phpstan.dumpType', $errors[0]->getIdentifier());
3535
self::assertSame(7, $errors[1]->getLine());
36+
self::assertSame('Something else 🔧', $errors[1]->getMessage());
3637
}
3738

3839
public function testExtractTopLevelErrorsWhenNoFileErrors(): void

0 commit comments

Comments
 (0)