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

Commit

Permalink
Defaults non existing versions to default docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Arko Elsenaar committed Oct 24, 2022
1 parent 6ef18ad commit fe68f32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
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

0 comments on commit fe68f32

Please sign in to comment.