Final Class Yiisoft\YiiDevTool\App\Command\AddChangelogCommand
| Inheritance | Yiisoft\YiiDevTool\App\Command\AddChangelogCommand » Yiisoft\YiiDevTool\App\Component\Console\PackageCommand » Symfony\Component\Console\Command\Command |
|---|
Public Methods
| Method | Description | Defined By |
|---|---|---|
| getApplication() | Yiisoft\YiiDevTool\App\Component\Console\PackageCommand |
Protected Methods
Method Details
Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::afterProcessingPackages()
Override this method in a subclass if you want to do something after processing the packages.
For example, link the packages with each other.
| protected void afterProcessingPackages ( \Symfony\Component\Console\Input\InputInterface $input ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
protected function afterProcessingPackages(InputInterface $input): void
{
}
Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::areTargetPackagesSpecifiedExplicitly()
| protected boolean areTargetPackagesSpecifiedExplicitly ( ) |
protected function areTargetPackagesSpecifiedExplicitly(): bool
{
if ($this->targetPackagesSpecifiedExplicitly === null) {
throw new RuntimeException('Target packages are not initialized.');
}
return $this->targetPackagesSpecifiedExplicitly;
}
| protected void beforeProcessingPackages ( \Symfony\Component\Console\Input\InputInterface $input ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
protected function beforeProcessingPackages(InputInterface $input): void
{
$this->message = $input->getArgument('message');
$this->type = $input->getArgument('type');
$this->prId = $input->getOption('pull-request-id');
}
| protected boolean checkSSHConnection ( ) |
protected function checkSSHConnection(): bool
{
$process = new Process(['ssh', '-T', 'git@github.com']);
$process
->setTimeout(null)
->run();
if ($process->getExitCode() !== 1) {
$this
->getIO()
->error([
'Checking access to github.com ... DENIED',
'Error: ' . $process->getErrorOutput(),
'Seems like you have not installed SSH key to you Github account.',
'Key is required to work with repository via SSH.',
'See here for instructions: https://docs.github.com/en/github/authenticating-to-github/adding-a-new-ssh-key-to-your-github-account',
]);
return false;
}
return true;
}
| protected mixed configure ( ) |
protected function configure()
{
$this
->setName('changelog/add')
->setDescription('Add an changelog entry')
->addArgument('type', InputArgument::REQUIRED, 'Change type', null)
->addArgument('message', InputArgument::REQUIRED, 'Entry text')
->addOption('pull-request-id', 'pr', InputArgument::OPTIONAL, 'Pull request ID', null)
;
parent::configure();
}
| protected boolean doesPackageContainErrors ( Yiisoft\YiiDevTool\App\Component\Package\Package $package ) | ||
| $package | Yiisoft\YiiDevTool\App\Component\Package\Package | |
protected function doesPackageContainErrors(Package $package): bool
{
return $this->errorList->has($package);
}
| protected integer execute ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
| $output | \Symfony\Component\Console\Output\OutputInterface | |
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->initPackageList();
$this->initTargetPackages($input);
$io = $this->getIO();
$this->beforeProcessingPackages($input);
$packages = $this->getTargetPackages();
sort($packages);
foreach ($packages as $package) {
if ($this->isCurrentInstallationValid($package)) {
$this->processPackage($package);
}
}
$io->clearPreparedPackageHeader();
$this->afterProcessingPackages($input);
$this->showPackageErrors();
if ($io->nothingHasBeenOutput()) {
$message = $this->getMessageWhenNothingHasBeenOutput();
if ($message !== null) {
$io
->important()
->info($message);
}
}
return Command::SUCCESS;
}
Defined in: Yiisoft\YiiDevTool\App\Component\Console\PackageCommand::getAppRootDir()
Use this method to get a root directory of the tool.
Commands and components can be moved as a result of refactoring, so you should not rely on their location in the file system.
| protected string getAppRootDir ( ) | ||
| return | string |
Path to the root directory of the tool WITH a TRAILING SLASH. |
|---|---|---|
protected function getAppRootDir(): string
{
return rtrim($this
->getApplication()
->getRootDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
| public Yiisoft\YiiDevTool\App\YiiDevToolApplication getApplication ( ) | ||
| return | Yiisoft\YiiDevTool\App\YiiDevToolApplication | |
|---|---|---|
| protected Yiisoft\YiiDevTool\App\Component\Package\PackageErrorList getErrorsList ( ) |
protected function getErrorsList(): PackageErrorList
{
return $this->errorList;
}
| protected string getExampleCommandPrefix ( ) | ||
| return | string |
Console command prefix that works in current environment. |
|---|---|---|
protected function getExampleCommandPrefix(): string
{
$shell = getenv('SHELL');
$isBash = ($shell && stripos($shell, 'bash')) !== false;
return $isBash ? './' : '';
}
| protected Yiisoft\YiiDevTool\App\Component\Console\OutputManager getIO ( ) |
protected function getIO(): OutputManager
{
if ($this->io === null) {
throw new RuntimeException('IO is not initialized.');
}
return $this->io;
}
| protected string|null getMessageWhenNothingHasBeenOutput ( ) |
protected function getMessageWhenNothingHasBeenOutput(): ?string
{
return '<success>✔ Done</success>';
}
| protected Yiisoft\YiiDevTool\App\Component\Package\PackageList getPackageList ( ) |
protected function getPackageList(): PackageList
{
return $this->packageList;
}
| protected Yiisoft\YiiDevTool\App\Component\Package\Package[] getTargetPackages ( ) |
protected function getTargetPackages(): array
{
if ($this->targetPackages === null) {
throw new RuntimeException('Target packages are not initialized.');
}
return $this->targetPackages;
}
| protected void initPackageList ( ) |
protected function initPackageList(): void
{
$io = $this->getIO();
try {
$ownerPackages = require $this->getAppRootDir() . 'owner-packages.php';
if (!preg_match('/^[a-z0-9][a-z0-9-]*[a-z0-9]$/i', $ownerPackages)) {
$io->error([
'The packages owner can only contain the characters [a-z0-9-], and the character \'-\' cannot appear at the beginning or at the end.',
'See <file>owner-packages.php</file> to set the packages owner.',
]);
exit(1);
}
$packagesRootDir = $this->getApplication()->getConfig('packagesRootDir') ?? $this->getAppRootDir() . 'dev';
$this->packageList = new PackageList(
$ownerPackages,
$this->getAppRootDir() . 'packages.php',
packagesRootDir: $packagesRootDir,
);
$this->errorList = new PackageErrorList();
} catch (InvalidArgumentException $e) {
$io->error([
'Invalid local package configuration <file>packages.local.php</file>',
$e->getMessage(),
'See <file>packages.local.php.example</file> for configuration examples.',
]);
exit(1);
}
}
| protected void initTargetPackages ( \Symfony\Component\Console\Input\InputInterface $input ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
protected function initTargetPackages(InputInterface $input): void
{
if ($this->packageList === null) {
throw new RuntimeException('Package list is not initialized.');
}
$io = $this->getIO();
$commaSeparatedPackageIds = $input->getArgument('packages');
if ($commaSeparatedPackageIds === null) {
$this->targetPackagesSpecifiedExplicitly = false;
$this->targetPackages = $this->packageList->getEnabledPackages();
return;
}
$targetPackageIds = array_unique(explode(',', $commaSeparatedPackageIds));
$problemsFound = false;
$targetPackages = [];
foreach ($targetPackageIds as $targetPackageId) {
$package = $this->packageList->getPackage($targetPackageId);
if ($package === null) {
$io->error("Package <package>$targetPackageId</package> not found in <file>packages.php</file>");
$problemsFound = true;
continue;
}
if ($package->disabled()) {
$io->error("Package <package>$targetPackageId</package> disabled in <file>packages.local.php</file>");
$problemsFound = true;
continue;
}
$targetPackages[] = $package;
}
if ($problemsFound) {
exit(1);
}
$this->targetPackagesSpecifiedExplicitly = true;
$this->targetPackages = $targetPackages;
}
| protected mixed initialize ( \Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output ) | ||
| $input | \Symfony\Component\Console\Input\InputInterface | |
| $output | \Symfony\Component\Console\Output\OutputInterface | |
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->io = new OutputManager(new YiiDevToolStyle($input, $output));
}
| protected void processPackage ( Yiisoft\YiiDevTool\App\Component\Package\Package $package ) | ||
| $package | Yiisoft\YiiDevTool\App\Component\Package\Package | |
protected function processPackage(Package $package): void
{
$io = $this->getIO();
$loweredTypes = array_map(fn (string $type) => strtolower($type), Changelog::TYPES);
if (!in_array(strtolower($this->type), $loweredTypes, true)) {
$io->error(
sprintf(
'The type argument value must be one of the following: %s. "%s" given',
implode(', ', Changelog::TYPES),
$this->type
)
);
return;
}
$io->preparePackageHeader($package, 'Adding the changelog entry to {package}');
$git = $package->getGitWorkingCopy();
$currentVersion = $this->getCurrentVersion($git);
if ($currentVersion->asString() === '') {
$io->info('There is currently no release.');
} else {
$io->info("Current version is $currentVersion.");
}
$messageParts = [];
$messageParts[] = ucfirst($this->type);
if ($this->prId) {
$messageParts[] = ' #' . $this->prId;
}
$messageParts[] = ': ';
$messageParts[] = $this->message;
$text = implode('', $messageParts);
$changelogPath = $package->getPath() . '/CHANGELOG.md';
$changelog = new Changelog($changelogPath);
$io->info(sprintf(
'Adding the entry "%s" into "%s".',
$text,
$changelogPath,
));
try {
$changelog->addEntry($text);
} catch (\InvalidArgumentException $e) {
$io->error($e);
$this->registerPackageError($package, $e->getMessage(), 'adding an changelog entry');
}
}
| protected void registerPackageError ( Yiisoft\YiiDevTool\App\Component\Package\Package $package, string $message, string $during ) | ||
| $package | Yiisoft\YiiDevTool\App\Component\Package\Package | |
| $message | string | |
| $during | string | |
protected function registerPackageError(Package $package, string $message, string $during): void
{
$this->errorList->set($package, $message, $during);
}
Signup or Login in order to comment.