From 96d183fabb0986c677582c8799182931a7a40b7f Mon Sep 17 00:00:00 2001 From: "tan.nguyen" Date: Wed, 6 Mar 2024 15:24:02 +0700 Subject: [PATCH] Add debug mode. --- src/Artifact.php | 34 ++++++++++++---------------------- src/GitTrait.php | 4 ---- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/src/Artifact.php b/src/Artifact.php index 4d04266..e5e4f2e 100644 --- a/src/Artifact.php +++ b/src/Artifact.php @@ -4,7 +4,11 @@ namespace DrevOps\GitArtifact; +use GitWrapper\EventSubscriber\GitLoggerEventSubscriber; use GitWrapper\GitWrapper; +use Monolog\Handler\StreamHandler; +use Monolog\Level; +use Monolog\Logger; use SplFileInfo; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Filesystem\Filesystem; @@ -18,10 +22,7 @@ */ class Artifact { - use GitTrait { - gitCommandRun as gitCommandRunFromTrait; - } - + use GitTrait; use TokenTrait; /** @@ -126,7 +127,7 @@ class Artifact */ protected $now; - /** + /** * Artifact constructor. * @param GitWrapper $gitWrapper * Git wrapper. @@ -138,10 +139,15 @@ class Artifact public function __construct( GitWrapper $gitWrapper, Filesystem $fsFileSystem, - protected OutputInterface $output + protected OutputInterface $output, ) { $this->fsFileSystem = $fsFileSystem; $this->gitWrapper = $gitWrapper; + if ($this->isDebug()) { + $logger = new Logger('git'); + $logger->pushHandler(new StreamHandler('php://stdout', Level::Debug)); + $this->gitWrapper->addLoggerEventSubscriber(new GitLoggerEventSubscriber($logger)); + } } /** @@ -968,20 +974,4 @@ protected function decorationCharacter(string $nonDecorated, string $decorated): return $decorated; } - - - protected function gitCommandRun( - string $location, - string $command, - string $errorMessage = '', - bool $noDebug = true - ): string { - if ($this->isDebug() || $noDebug !== false) { - $result = $this->gitCommandRunFromTrait($location, $command, $errorMessage, false); - } else { - $result = $this->gitCommandRunFromTrait($location, $command, $errorMessage); - } - $this->printDebug($result); - return $result; - } } diff --git a/src/GitTrait.php b/src/GitTrait.php index c165f8c..857057c 100644 --- a/src/GitTrait.php +++ b/src/GitTrait.php @@ -318,9 +318,6 @@ protected function gitGetTags(string $location): array * Command to run. * @param string $errorMessage * Optional error message. - * @param bool $noDebug - * Flag to enforce no-debug mode. Used by commands that use output for - * values. * * @return string * Stdout. @@ -331,7 +328,6 @@ protected function gitCommandRun( string $location, string $command, string $errorMessage = '', - bool $noDebug = true ): string { $command = '--no-pager '.$command; try {