Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Defaults non existing versions to default docs #5

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class MessageParser {
"vite",
];

protected $versions = [
"9.x",
"8.x",
"7.x",
"6.x",
];

public function __invoke($message)
{
$content = strtolower($message->content);
Expand All @@ -103,12 +110,12 @@ public function __invoke($message)
$query = substr($content, 5);

// Check if version is available in command
$pattern = '/\b([6-9]\.x)\b/'; // only match 6.x to 9.x
$pattern = '/\b([0-9]+\.([0-9]|[x])+)\b/';
preg_match($pattern, $query, $matches);

if ($matches) {
$query = preg_replace($pattern, '', $query);
$version = $matches[0];
$version = in_array($matches[0], $this->versions) ? $matches[0] : null;
}

$query = trim($query);
Expand Down
4 changes: 3 additions & 1 deletion tests/MessageParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ public function messageInputProvider()
["docs vite", "<https://laravel.com/docs/vite>"],
["docs 9.x csrf", "<https://laravel.com/docs/9.x/csrf>"],
["docs 8.x csrf", "<https://laravel.com/docs/8.x/csrf>"],
["docs 10.x csrf", false],
["docs 10.x csrf", "<https://laravel.com/docs/csrf>"],
["docs 5.4 csrf", "<https://laravel.com/docs/csrf>"],
["docs csrf 5.4", "<https://laravel.com/docs/csrf>"],
["docs csrf 9.x", "<https://laravel.com/docs/9.x/csrf>"],
];
}
Expand Down