+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Aeon/Automation/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
use Aeon\Automation\Changes\Detector\HTMLChangesDetector;
use Aeon\Automation\Changes\Detector\PrefixDetector;
use Aeon\Automation\Changes\Detector\PrioritizedDetector;
use Psr\Log\LoggerInterface;

final class Configuration
{
private LoggerInterface $logger;

private string $rootDir;

private array $defaultPaths;
Expand All @@ -21,8 +24,9 @@ final class Configuration

private ?\DOMDocument $config;

public function __construct(string $rootDir, array $defaultPaths, ?string $path = null)
public function __construct(LoggerInterface $logger, string $rootDir, array $defaultPaths, ?string $path = null)
{
$this->logger = $logger;
$this->rootDir = $rootDir;
$this->defaultPaths = $defaultPaths;
$this->path = $path;
Expand Down Expand Up @@ -92,12 +96,16 @@ private function config() : \DOMDocument
if ($configFilePath === null || !\file_exists($configFilePath)) {
$this->config = new \DOMDocument();

$this->logger->info('Config file path not found.');

return $this->config;
}

$this->config = new \DOMDocument();
$this->config->loadXML(\file_get_contents($configFilePath));

$this->logger->info('Config file path: ' . $configFilePath);

return $this->config;
}
}
40 changes: 25 additions & 15 deletions src/Aeon/Automation/Console/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Http\Message\Formatter\FullHttpMessageFormatter;
use Http\Message\Formatter\SimpleFormatter;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Console\Command\Command;
Expand All @@ -39,6 +40,8 @@ abstract class AbstractCommand extends Command

private ?CacheItemPoolInterface $githubCache;

private ?LoggerInterface $logger;

private ?Calendar $calendar;

public function __construct(string $rootDir, array $defaultConfigPaths = [])
Expand All @@ -52,6 +55,7 @@ public function __construct(string $rootDir, array $defaultConfigPaths = [])
$this->httpCache = null;
$this->githubCache = null;
$this->calendar = null;
$this->logger = null;
}

public function githubClient() : GitHubClient
Expand Down Expand Up @@ -124,38 +128,44 @@ protected function interact(InputInterface $input, OutputInterface $output) : vo

protected function initialize(InputInterface $input, OutputInterface $output) : void
{
$this->configuration = new Configuration($this->rootDir, $this->defaultConfigPaths, $input->getOption('configuration'));
$verbosityLevelMap = [
LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
];

$formatLevelMap = [
LogLevel::ERROR => ConsoleLogger::ERROR,
LogLevel::CRITICAL => ConsoleLogger::ERROR,
LogLevel::INFO => ConsoleLogger::INFO,
];

$this->logger = new ConsoleLogger($output, $verbosityLevelMap, $formatLevelMap);

$this->configuration = new Configuration($this->logger, $this->rootDir, $this->defaultConfigPaths, $input->getOption('configuration'));
$cachePath = $input->getOption('cache-path');

if (\getenv('AEON_AUTOMATION_CACHE_DIR')) {
$cachePath = \getenv('AEON_AUTOMATION_CACHE_DIR');
}

$this->logger->info('Cache directory: ' . $cachePath);

$this->httpCache = $this->httpCache === null ? new FilesystemAdapter('http-cache', 0, $cachePath . \DIRECTORY_SEPARATOR . 'automation-cache') : $this->httpCache;
$this->httpCache->setLogger($this->logger);

$this->githubCache = $this->githubCache === null ? new FilesystemAdapter('github-cache', 0, $cachePath . \DIRECTORY_SEPARATOR . 'automation-cache') : $this->githubCache;
$this->githubCache->setLogger($this->logger);

$this->initializeCalendar();
$this->initializeGithub($this->httpCache, $output, $input);
$this->initializeGithub($this->httpCache, $this->logger, $output, $input);
}

private function initializeGithub(CacheItemPoolInterface $cache, OutputInterface $output, InputInterface $input) : void
private function initializeGithub(CacheItemPoolInterface $cache, LoggerInterface $logger, OutputInterface $output, InputInterface $input) : void
{
if ($this->github !== null) {
return;
}

$verbosityLevelMap = [
LogLevel::INFO => OutputInterface::VERBOSITY_VERBOSE,
];

$formatLevelMap = [
LogLevel::ERROR => ConsoleLogger::ERROR,
LogLevel::CRITICAL => ConsoleLogger::ERROR,
LogLevel::INFO => ConsoleLogger::INFO,
];

$logger = new ConsoleLogger($output, $verbosityLevelMap, $formatLevelMap);

switch ($output->getVerbosity()) {
case OutputInterface::VERBOSITY_VERY_VERBOSE:
$formatter = new SimpleFormatter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
use Aeon\Calendar\Gregorian\DateTime;
use Aeon\Calendar\Gregorian\Day;
use Monolog\Test\TestCase;
use Psr\Log\NullLogger;

final class ManipulatorTest extends TestCase
{
public function test_add_new_changed_to_unreleased_release() : void
{
$factory = new Release\FormatterFactory(new Configuration(\getenv('AUTOMATION_ROOT_DIR'), []));
$factory = new Release\FormatterFactory(new Configuration(new NullLogger(), \getenv('AUTOMATION_ROOT_DIR'), []));
$formatter = $factory->create('markdown', 'keepachangelog');

$release = new Release('Unreleased', Day::fromString('2021-01-4'));
Expand Down Expand Up @@ -135,7 +136,7 @@ public function test_keep_original_order_of_changes() : void
MARKDOWN
);

$factory = new Release\FormatterFactory(new Configuration(\getenv('AUTOMATION_ROOT_DIR'), []));
$factory = new Release\FormatterFactory(new Configuration(new NullLogger(), \getenv('AUTOMATION_ROOT_DIR'), []));
$formatter = $factory->create('markdown', 'keepachangelog');

$this->assertSame($input, $formatter->formatRelease($source->releases()->all()[0]));
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载