diff --git a/src/ZM/Command/Generate/TextGenerateCommand.php b/src/ZM/Command/Generate/TextGenerateCommand.php index 28989a5c..2aec4f8f 100644 --- a/src/ZM/Command/Generate/TextGenerateCommand.php +++ b/src/ZM/Command/Generate/TextGenerateCommand.php @@ -4,9 +4,11 @@ declare(strict_types=1); namespace ZM\Command\Generate; +use Jelix\Version\VersionComparator; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Input\InputArgument; use ZM\Command\Command; +use ZM\Utils\ZMRequest; #[AsCommand(name: 'generate:text', description: '生成一些文本(内部)')] class TextGenerateCommand extends Command @@ -23,6 +25,7 @@ class TextGenerateCommand extends Command { return match ($this->input->getArgument('name')) { 'class-alias-md' => $this->generateClassAliasDoc(), + 'update-log-md' => $this->generateUpdateLogs(), default => static::FAILURE, }; } @@ -49,4 +52,27 @@ class TextGenerateCommand extends Command } return static::SUCCESS; } + + private function generateUpdateLogs(): int + { + date_default_timezone_set(config('global.runtime.timezone', 'UTC')); + $api = ZMRequest::get('https://api.github.com/repos/zhamao-robot/zhamao-framework/releases', ['User-Agent' => 'ZMFramework']); + if ($api === false) { + $this->error('获取更新日志失败'); + return static::FAILURE; + } + $json = json_decode($api, true); + $line = '# 更新日志' . "\r\n\r\n> 本页面由框架自动生成\r\n\r\n"; + foreach ($json as $v) { + $version = $v['tag_name']; + if (str_starts_with($version, '2.')) { + continue; + } + $time = '> 更新时间:' . date('Y-m-d', strtotime($v['published_at'])); + $line .= '## v' . $v['tag_name'] . "\r\n\r\n" . $time . "\r\n\r\n" . trim(str_replace("## What's Changed", '', $v['body'])) . "\r\n\r\n"; + } + $line = str_replace("\r\n", "\n", $line); + file_put_contents(FRAMEWORK_ROOT_DIR . '/docs/update/v3.md', $line); + return static::SUCCESS; + } }