Final Class Yiisoft\YiiDevTool\App\Command\Release\WhatCommand
| Inheritance | Yiisoft\ |
|---|---|
| Uses Traits | Yiisoft\ |
Public Methods
Protected Methods
Method Details
| public mixed __construct ( ?\ | ||
| $gitHub | ?\ |
|
public function __construct(private ?GitHubReleaseInspectorInterface $gitHub = null)
{
parent::__construct();
}
| protected void configure ( ) |
protected function configure(): void
{
$this
->setName('release:what')
->setDescription('Find packages that are ready to release');
}
| protected integer execute ( \ | ||
| $input | \ |
|
| $output | \ |
|
protected function execute(InputInterface $input, OutputInterface $output): int
{
$this->initPackageList();
$ready = [];
$blocked = [];
$candidates = [];
foreach ($this->packageList->getInstalledAndEnabledPackages() as $package) {
if (!$package->isGitRepositoryCloned()) {
continue;
}
try {
$candidate = $this->inspectLocalCandidate($package);
} catch (Throwable $e) {
$blocked[] = [$package->getName(), '', $e->getMessage()];
continue;
}
if ($candidate === null) {
continue;
}
$candidates[$package->getName()] = $candidate;
}
$defaultBranchRequests = [];
foreach ($candidates as $candidate) {
$key = $candidate['remoteKey'];
$defaultBranchRequests[$key] ??= [
'vendor' => $candidate['vendor'],
'repository' => $candidate['repository'],
];
}
$defaultBranches = [];
$remoteError = null;
if ($defaultBranchRequests !== []) {
try {
$defaultBranches = $this->getGitHub()->getDefaultBranches($defaultBranchRequests);
} catch (Throwable $e) {
$remoteError = $e->getMessage();
}
}
$detailRequests = [];
foreach ($candidates as $packageName => $candidate) {
if ($remoteError !== null) {
$candidates[$packageName]['problems'][] = $remoteError;
continue;
}
$key = $candidate['remoteKey'];
if (!isset($defaultBranches[$key])) {
$candidates[$packageName]['problems'][] = 'GitHub default branch result is missing.';
continue;
}
if ($candidate['head'] !== $defaultBranches[$key]['sha']) {
$candidates[$packageName]['problems'][] = sprintf(
'HEAD does not match origin/%s.',
$defaultBranches[$key]['branch'],
);
continue;
}
if ($candidate['problems'] !== []) {
continue;
}
if (isset($detailRequests[$key])) {
$detailRequests[$key]['issues'] = array_values(array_unique([
...$detailRequests[$key]['issues'],
...$candidate['issues'],
]));
} else {
$detailRequests[$key] = [
'vendor' => $candidate['vendor'],
'repository' => $candidate['repository'],
'sha' => $candidate['head'],
'issues' => $candidate['issues'],
];
}
}
$detailResults = [];
if ($detailRequests !== []) {
try {
$detailResults = $this->getGitHub()->inspect($detailRequests);
} catch (Throwable $e) {
foreach ($candidates as $packageName => $candidate) {
if (isset($detailRequests[$candidate['remoteKey']])) {
$candidates[$packageName]['problems'][] = $e->getMessage();
}
}
}
}
foreach ($candidates as $packageName => $candidate) {
$key = $candidate['remoteKey'];
if ($candidate['problems'] === [] && isset($detailResults[$key])) {
array_push($candidate['problems'], ...$this->checkRemote($candidate, $detailResults[$key]));
} elseif ($candidate['problems'] === [] && isset($detailRequests[$key])) {
$candidate['problems'][] = 'GitHub inspection result is missing.';
}
$row = [$packageName, $candidate['version'], implode("\n" , $candidate['summary'])];
if ($candidate['problems'] === []) {
$ready[] = $row;
} else {
$blocked[] = [
$packageName,
$candidate['version'],
implode("\n" , $candidate['problems']),
];
}
}
$this->render($output, $ready, $blocked);
return $blocked === [] ? Command::SUCCESS : Command::FAILURE;
}
| protected string getAppRootDir ( ) |
protected function getAppRootDir(): string
{
return rtrim($this->getApplication()->getRootDir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}
| public Yiisoft\ | ||
| return | Yiisoft\ |
|
|---|---|---|
| public string getGitHubToken ( boolean $validate = true ) | ||
| $validate | boolean | |
public function getGitHubToken(bool $validate = true): string
{
if ($this->gitHubToken !== null) {
return $this->gitHubToken;
}
$io = $this->getIO();
$tokenFile = $this->getAppRootDir() . 'config/github.token';
if (!file_exists($tokenFile)) {
$io->error([
"There's no $tokenFile.",
'<href=https://github.com/settings/tokens>Please create a GitHub token</> and put it there.',
]);
exit(Command::FAILURE);
}
$token = trim(file_get_contents($tokenFile));
if (empty($token)) {
$io->error([
"$tokenFile exists but is empty.",
'<href=https://github.com/settings/tokens>Please create a GitHub token</> and put it there.',
]);
exit(Command::FAILURE);
}
if (!$validate) {
return $token;
}
// Test the token by making an authenticated request
$client = new Client();
$client->authenticate($token, null, AuthMethod::ACCESS_TOKEN);
try {
$client->currentUser()->show();
} catch (Exception $e) {
$io->error([
"Failed to authenticate with GitHub using the provided token from $tokenFile.",
'<href=https://github.com/settings/tokens>Please make sure the token is valid '
. 'and has the required permissions</>.',
'Error: ' . $e->getMessage(),
]);
exit(Command::FAILURE);
}
$this->gitHubToken = $token;
return $token;
}
| protected Yiisoft\ |
protected function getIO(): OutputManager
{
if ($this->io === null) {
throw new RuntimeException('IO is not initialized.');
}
return $this->io;
}
| protected void initialize ( \ | ||
| $input | \ |
|
| $output | \ |
|
protected function initialize(InputInterface $input, OutputInterface $output): void
{
$this->io = new OutputManager(new YiiDevToolStyle($input, $output));
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.