-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6709227
commit 1f28964
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Dockworker\Robo\Plugin\Commands; | ||
|
||
use Dockworker\DockworkerCommands; | ||
use Dockworker\IO\DockworkerIOTrait; | ||
use Dockworker\Logs\LogCheckerTrait; | ||
use Dockworker\Logs\LogErrorStringsTrait; | ||
|
||
/** | ||
* Provides commands to check a log file for errors. | ||
*/ | ||
class LogCheckCommands extends DockworkerCommands | ||
{ | ||
use DockworkerIOTrait; | ||
use LogCheckerTrait; | ||
use LogErrorStringsTrait; | ||
|
||
/** | ||
* Checks a log file for errors. | ||
* | ||
* @param string $file_path | ||
* The path to the log file. | ||
* | ||
* @command logs:check-file | ||
* @hidden | ||
*/ | ||
public function setupGitHooks(string $file_path): void | ||
{ | ||
[$errors_pattern, $exceptions_pattern] = $this->getAllLogErrorStrings(); | ||
$logs = file_get_contents($file_path); | ||
$matched_error = ''; | ||
if ( | ||
$this->logsHaveErrors( | ||
$logs, | ||
$errors_pattern, | ||
$exceptions_pattern, | ||
$matched_error | ||
) | ||
) { | ||
$this->dockworkerIO->error( | ||
sprintf( | ||
'Errors detected in logs. [%s] found in output.', | ||
trim($matched_error) | ||
) | ||
); | ||
exit(1); | ||
} | ||
else { | ||
$this->dockworkerIO->writeln('No errors detected in logs.'); | ||
} | ||
} | ||
} |