Skip to content

Commit

Permalink
Add debug mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
tannguyen04 committed Mar 6, 2024
1 parent 90fd452 commit 96d183f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
34 changes: 12 additions & 22 deletions src/Artifact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,10 +22,7 @@
*/
class Artifact
{
use GitTrait {
gitCommandRun as gitCommandRunFromTrait;
}

use GitTrait;
use TokenTrait;

/**
Expand Down Expand Up @@ -126,7 +127,7 @@ class Artifact
*/
protected $now;

/**
/**
* Artifact constructor.
* @param GitWrapper $gitWrapper
* Git wrapper.
Expand All @@ -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));
}
}

/**
Expand Down Expand Up @@ -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;
}
}
4 changes: 0 additions & 4 deletions src/GitTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -331,7 +328,6 @@ protected function gitCommandRun(
string $location,
string $command,
string $errorMessage = '',
bool $noDebug = true
): string {
$command = '--no-pager '.$command;
try {
Expand Down

0 comments on commit 96d183f

Please sign in to comment.