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

Commit bb4053f

Browse files
authored
Merge pull request #5 from shitware-ltd/main
Defaults non existing versions to default docs
2 parents 6bbf21b + fe68f32 commit bb4053f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/MessageParser.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ class MessageParser {
9292
"vite",
9393
];
9494

95+
protected $versions = [
96+
"9.x",
97+
"8.x",
98+
"7.x",
99+
"6.x",
100+
];
101+
95102
public function __invoke($message)
96103
{
97104
$content = strtolower($message->content);
@@ -103,12 +110,12 @@ public function __invoke($message)
103110
$query = substr($content, 5);
104111

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

109116
if ($matches) {
110117
$query = preg_replace($pattern, '', $query);
111-
$version = $matches[0];
118+
$version = in_array($matches[0], $this->versions) ? $matches[0] : null;
112119
}
113120

114121
$query = trim($query);

tests/MessageParserTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ public function messageInputProvider()
127127
["docs vite", "<https://laravel.com/docs/vite>"],
128128
["docs 9.x csrf", "<https://laravel.com/docs/9.x/csrf>"],
129129
["docs 8.x csrf", "<https://laravel.com/docs/8.x/csrf>"],
130-
["docs 10.x csrf", false],
130+
["docs 10.x csrf", "<https://laravel.com/docs/csrf>"],
131+
["docs 5.4 csrf", "<https://laravel.com/docs/csrf>"],
132+
["docs csrf 5.4", "<https://laravel.com/docs/csrf>"],
131133
["docs csrf 9.x", "<https://laravel.com/docs/9.x/csrf>"],
132134
];
133135
}

0 commit comments

Comments
 (0)