From d383848668dc2585754a3e2de72ef886f74ce084 Mon Sep 17 00:00:00 2001 From: Arko Elsenaar Date: Mon, 24 Oct 2022 20:07:41 +0200 Subject: [PATCH 1/2] Adds version support --- src/MessageParser.php | 12 ++- tests/MessageParserTest.php | 180 ++++++++++++++++++------------------ 2 files changed, 103 insertions(+), 89 deletions(-) diff --git a/src/MessageParser.php b/src/MessageParser.php index cd95b1b..944ec05 100644 --- a/src/MessageParser.php +++ b/src/MessageParser.php @@ -95,16 +95,26 @@ 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 ($version = $matches[0] ?? "9.x") // default to 9.x if no version is given + $query = preg_replace($pattern, '', $query); + + $query = trim($query); + if($trigger === "docs ") { if(in_array($query, $this->docs)){ - return ""; + return ""; } } diff --git a/tests/MessageParserTest.php b/tests/MessageParserTest.php index e76b58e..0cac26f 100644 --- a/tests/MessageParserTest.php +++ b/tests/MessageParserTest.php @@ -37,94 +37,98 @@ public function messageInputProvider() ["bad input", false], ["homestead", false], ["docs pageDoesn'tExist", false], - ["dOcS ArTiSan", ""], - ["docs artisan", ""], - ["docs authentication", ""], - ["docs authorization", ""], - ["docs billing", ""], - ["docs blade", ""], - ["docs broadcasting", ""], - ["docs cache", ""], - ["docs cashier-paddle", ""], - ["docs collections", ""], - ["docs configuration", ""], - ["docs console-tests", ""], - ["docs container", ""], - ["docs contracts", ""], - ["docs contributions", ""], - ["docs controllers", ""], - ["docs csrf", ""], - ["docs database-testing", ""], - ["docs database", ""], - ["docs deployment", ""], - ["docs documentation", ""], - ["docs dusk", ""], - ["docs eloquent-collections", ""], - ["docs eloquent-mutators", ""], - ["docs eloquent-relationships", ""], - ["docs eloquent-resources", ""], - ["docs eloquent-serialization", ""], - ["docs eloquent", ""], - ["docs encryption", ""], - ["docs envoy", ""], - ["docs errors", ""], - ["docs events", ""], - ["docs facades", ""], - ["docs filesystem", ""], - ["docs fortify", ""], - ["docs frontend", ""], - ["docs hashing", ""], - ["docs helpers", ""], - ["docs homestead", ""], - ["docs horizon", ""], - ["docs http-client", ""], - ["docs http-tests", ""], - ["docs installation", ""], - ["docs license", ""], - ["docs lifecycle", ""], - ["docs localization", ""], - ["docs logging", ""], - ["docs mail", ""], - ["docs middleware", ""], - ["docs migrations", ""], - ["docs mix", ""], - ["docs mocking", ""], - ["docs notifications", ""], - ["docs octane", ""], - ["docs packages", ""], - ["docs pagination", ""], - ["docs passport", ""], - ["docs passwords", ""], - ["docs pint", ""], - ["docs providers", ""], - ["docs queries", ""], - ["docs queues", ""], - ["docs rate-limiting", ""], - ["docs readme", ""], - ["docs redirects", ""], - ["docs redis", ""], - ["docs releases", ""], - ["docs requests", ""], - ["docs responses", ""], - ["docs routing", ""], - ["docs sail", ""], - ["docs sanctum", ""], - ["docs scheduling", ""], - ["docs scout", ""], - ["docs seeding", ""], - ["docs session", ""], - ["docs socialite", ""], - ["docs starter-kits", ""], - ["docs structure", ""], - ["docs telescope", ""], - ["docs testing", ""], - ["docs upgrade", ""], - ["docs urls", ""], - ["docs valet", ""], - ["docs validation", ""], - ["docs verification", ""], - ["docs views", ""], - ["docs vite", ""], + ["dOcS ArTiSan", ""], + ["docs artisan", ""], + ["docs authentication", ""], + ["docs authorization", ""], + ["docs billing", ""], + ["docs blade", ""], + ["docs broadcasting", ""], + ["docs cache", ""], + ["docs cashier-paddle", ""], + ["docs collections", ""], + ["docs configuration", ""], + ["docs console-tests", ""], + ["docs container", ""], + ["docs contracts", ""], + ["docs contributions", ""], + ["docs controllers", ""], + ["docs csrf", ""], + ["docs database-testing", ""], + ["docs database", ""], + ["docs deployment", ""], + ["docs documentation", ""], + ["docs dusk", ""], + ["docs eloquent-collections", ""], + ["docs eloquent-mutators", ""], + ["docs eloquent-relationships", ""], + ["docs eloquent-resources", ""], + ["docs eloquent-serialization", ""], + ["docs eloquent", ""], + ["docs encryption", ""], + ["docs envoy", ""], + ["docs errors", ""], + ["docs events", ""], + ["docs facades", ""], + ["docs filesystem", ""], + ["docs fortify", ""], + ["docs frontend", ""], + ["docs hashing", ""], + ["docs helpers", ""], + ["docs homestead", ""], + ["docs horizon", ""], + ["docs http-client", ""], + ["docs http-tests", ""], + ["docs installation", ""], + ["docs license", ""], + ["docs lifecycle", ""], + ["docs localization", ""], + ["docs logging", ""], + ["docs mail", ""], + ["docs middleware", ""], + ["docs migrations", ""], + ["docs mix", ""], + ["docs mocking", ""], + ["docs notifications", ""], + ["docs octane", ""], + ["docs packages", ""], + ["docs pagination", ""], + ["docs passport", ""], + ["docs passwords", ""], + ["docs pint", ""], + ["docs providers", ""], + ["docs queries", ""], + ["docs queues", ""], + ["docs rate-limiting", ""], + ["docs readme", ""], + ["docs redirects", ""], + ["docs redis", ""], + ["docs releases", ""], + ["docs requests", ""], + ["docs responses", ""], + ["docs routing", ""], + ["docs sail", ""], + ["docs sanctum", ""], + ["docs scheduling", ""], + ["docs scout", ""], + ["docs seeding", ""], + ["docs session", ""], + ["docs socialite", ""], + ["docs starter-kits", ""], + ["docs structure", ""], + ["docs telescope", ""], + ["docs testing", ""], + ["docs upgrade", ""], + ["docs urls", ""], + ["docs valet", ""], + ["docs validation", ""], + ["docs verification", ""], + ["docs views", ""], + ["docs vite", ""], + ["docs 9.x csrf", ""], + ["docs 8.x csrf", ""], + ["docs 10.x csrf", false], + ["docs csrf 9.x", ""], ]; } } \ No newline at end of file From 6ef18ad277be5b2fb0394b2cbab6b8f045243bbe Mon Sep 17 00:00:00 2001 From: Arko Elsenaar Date: Mon, 24 Oct 2022 20:25:14 +0200 Subject: [PATCH 2/2] Removes the default version --- src/MessageParser.php | 9 +- tests/MessageParserTest.php | 176 ++++++++++++++++++------------------ 2 files changed, 95 insertions(+), 90 deletions(-) diff --git a/src/MessageParser.php b/src/MessageParser.php index 944ec05..426da5b 100644 --- a/src/MessageParser.php +++ b/src/MessageParser.php @@ -105,16 +105,21 @@ public function __invoke($message) // 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 ($version = $matches[0] ?? "9.x") // default to 9.x if no version is given + + 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 ""; - return ""; + return ""; } } diff --git a/tests/MessageParserTest.php b/tests/MessageParserTest.php index 0cac26f..2fa1396 100644 --- a/tests/MessageParserTest.php +++ b/tests/MessageParserTest.php @@ -37,94 +37,94 @@ public function messageInputProvider() ["bad input", false], ["homestead", false], ["docs pageDoesn'tExist", false], - ["dOcS ArTiSan", ""], - ["docs artisan", ""], - ["docs authentication", ""], - ["docs authorization", ""], - ["docs billing", ""], - ["docs blade", ""], - ["docs broadcasting", ""], - ["docs cache", ""], - ["docs cashier-paddle", ""], - ["docs collections", ""], - ["docs configuration", ""], - ["docs console-tests", ""], - ["docs container", ""], - ["docs contracts", ""], - ["docs contributions", ""], - ["docs controllers", ""], - ["docs csrf", ""], - ["docs database-testing", ""], - ["docs database", ""], - ["docs deployment", ""], - ["docs documentation", ""], - ["docs dusk", ""], - ["docs eloquent-collections", ""], - ["docs eloquent-mutators", ""], - ["docs eloquent-relationships", ""], - ["docs eloquent-resources", ""], - ["docs eloquent-serialization", ""], - ["docs eloquent", ""], - ["docs encryption", ""], - ["docs envoy", ""], - ["docs errors", ""], - ["docs events", ""], - ["docs facades", ""], - ["docs filesystem", ""], - ["docs fortify", ""], - ["docs frontend", ""], - ["docs hashing", ""], - ["docs helpers", ""], - ["docs homestead", ""], - ["docs horizon", ""], - ["docs http-client", ""], - ["docs http-tests", ""], - ["docs installation", ""], - ["docs license", ""], - ["docs lifecycle", ""], - ["docs localization", ""], - ["docs logging", ""], - ["docs mail", ""], - ["docs middleware", ""], - ["docs migrations", ""], - ["docs mix", ""], - ["docs mocking", ""], - ["docs notifications", ""], - ["docs octane", ""], - ["docs packages", ""], - ["docs pagination", ""], - ["docs passport", ""], - ["docs passwords", ""], - ["docs pint", ""], - ["docs providers", ""], - ["docs queries", ""], - ["docs queues", ""], - ["docs rate-limiting", ""], - ["docs readme", ""], - ["docs redirects", ""], - ["docs redis", ""], - ["docs releases", ""], - ["docs requests", ""], - ["docs responses", ""], - ["docs routing", ""], - ["docs sail", ""], - ["docs sanctum", ""], - ["docs scheduling", ""], - ["docs scout", ""], - ["docs seeding", ""], - ["docs session", ""], - ["docs socialite", ""], - ["docs starter-kits", ""], - ["docs structure", ""], - ["docs telescope", ""], - ["docs testing", ""], - ["docs upgrade", ""], - ["docs urls", ""], - ["docs valet", ""], - ["docs validation", ""], - ["docs verification", ""], - ["docs views", ""], - ["docs vite", ""], + ["dOcS ArTiSan", ""], + ["docs artisan", ""], + ["docs authentication", ""], + ["docs authorization", ""], + ["docs billing", ""], + ["docs blade", ""], + ["docs broadcasting", ""], + ["docs cache", ""], + ["docs cashier-paddle", ""], + ["docs collections", ""], + ["docs configuration", ""], + ["docs console-tests", ""], + ["docs container", ""], + ["docs contracts", ""], + ["docs contributions", ""], + ["docs controllers", ""], + ["docs csrf", ""], + ["docs database-testing", ""], + ["docs database", ""], + ["docs deployment", ""], + ["docs documentation", ""], + ["docs dusk", ""], + ["docs eloquent-collections", ""], + ["docs eloquent-mutators", ""], + ["docs eloquent-relationships", ""], + ["docs eloquent-resources", ""], + ["docs eloquent-serialization", ""], + ["docs eloquent", ""], + ["docs encryption", ""], + ["docs envoy", ""], + ["docs errors", ""], + ["docs events", ""], + ["docs facades", ""], + ["docs filesystem", ""], + ["docs fortify", ""], + ["docs frontend", ""], + ["docs hashing", ""], + ["docs helpers", ""], + ["docs homestead", ""], + ["docs horizon", ""], + ["docs http-client", ""], + ["docs http-tests", ""], + ["docs installation", ""], + ["docs license", ""], + ["docs lifecycle", ""], + ["docs localization", ""], + ["docs logging", ""], + ["docs mail", ""], + ["docs middleware", ""], + ["docs migrations", ""], + ["docs mix", ""], + ["docs mocking", ""], + ["docs notifications", ""], + ["docs octane", ""], + ["docs packages", ""], + ["docs pagination", ""], + ["docs passport", ""], + ["docs passwords", ""], + ["docs pint", ""], + ["docs providers", ""], + ["docs queries", ""], + ["docs queues", ""], + ["docs rate-limiting", ""], + ["docs readme", ""], + ["docs redirects", ""], + ["docs redis", ""], + ["docs releases", ""], + ["docs requests", ""], + ["docs responses", ""], + ["docs routing", ""], + ["docs sail", ""], + ["docs sanctum", ""], + ["docs scheduling", ""], + ["docs scout", ""], + ["docs seeding", ""], + ["docs session", ""], + ["docs socialite", ""], + ["docs starter-kits", ""], + ["docs structure", ""], + ["docs telescope", ""], + ["docs testing", ""], + ["docs upgrade", ""], + ["docs urls", ""], + ["docs valet", ""], + ["docs validation", ""], + ["docs verification", ""], + ["docs views", ""], + ["docs vite", ""], ["docs 9.x csrf", ""], ["docs 8.x csrf", ""], ["docs 10.x csrf", false],