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

Commit

Permalink
Merge pull request #4 from shitware-ltd/main
Browse files Browse the repository at this point in the history
Adds version support
  • Loading branch information
svpernova09 authored Oct 24, 2022
2 parents bf8839d + 6ef18ad commit 6bbf21b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,29 @@ class MessageParser {
public function __invoke($message)
{
$content = strtolower($message->content);

// Grab the first 4 chars for our trigger
$trigger = substr($content, 0, 5);

// Grab everything after the first 5 chars
$query = substr($content, 5);

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

if ($matches) {
$query = preg_replace($pattern, '', $query);
$version = $matches[0];
}

$query = trim($query);

if($trigger === "docs ")
{
if(in_array($query, $this->docs)){
if (isset($version))
return "<https://laravel.com/docs/$version/$query>";

return "<https://laravel.com/docs/$query>";
}
Expand Down
4 changes: 4 additions & 0 deletions tests/MessageParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ public function messageInputProvider()
["docs verification", "<https://laravel.com/docs/verification>"],
["docs views", "<https://laravel.com/docs/views>"],
["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 csrf 9.x", "<https://laravel.com/docs/9.x/csrf>"],
];
}
}

0 comments on commit 6bbf21b

Please sign in to comment.