mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-01 15:32:48 +08:00
refactor: 优化代码结构
This commit is contained in:
@@ -213,43 +213,39 @@ class VersionBase extends Command
|
|||||||
|
|
||||||
// 获取所有tags,按时间倒序排列
|
// 获取所有tags,按时间倒序排列
|
||||||
$tags = explode("\n", trim(shell_exec('git tag --sort=-creatordate')));
|
$tags = explode("\n", trim(shell_exec('git tag --sort=-creatordate')));
|
||||||
// 如果没有指定起始版本,则获取倒数第二个tag
|
|
||||||
|
if (empty($tags)) {
|
||||||
|
$output->error('没有找到任何tag');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$toTag = $tags[0]; // 最新的tag
|
||||||
if (empty($fromTag)) {
|
if (empty($fromTag)) {
|
||||||
if (count($tags) < 2) {
|
if (count($tags) < 2) {
|
||||||
$output->error('没有足够的tag来生成发布说明');
|
$output->error('没有足够的tag来生成发布说明');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fromTag = $tags[1]; // 倒数第二个tag
|
$fromTag = $tags[1]; // 倒数第二个tag
|
||||||
$toTag = $tags[0]; // 最新的tag
|
|
||||||
|
|
||||||
$output->info('未指定起始版本,使用倒数第二个tag: ' . $fromTag);
|
$output->info('未指定起始版本,使用倒数第二个tag: ' . $fromTag);
|
||||||
$output->info('到最新tag: ' . $toTag);
|
|
||||||
} else {
|
} else {
|
||||||
// 如果指定了fromTag,找到比fromTag新的最近的tag
|
if (!in_array($fromTag, $tags)) {
|
||||||
$toTag = null;
|
$output->error('指定的起始版本 ' . $fromTag . ' 不存在');
|
||||||
foreach ($tags as $tag) {
|
|
||||||
if (version_compare($tag, $fromTag, '>')) {
|
return;
|
||||||
$toTag = $tag;
|
}
|
||||||
break;
|
if (version_compare($fromTag, $toTag, '>=')) {
|
||||||
}
|
$output->error('指定的起始版本 ' . $fromTag . ' 不早于最新版本 ' . $toTag);
|
||||||
}
|
|
||||||
|
|
||||||
if ($toTag === null) {
|
|
||||||
$output->error('没有找到比 ' . $fromTag . ' 更新的tag');
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$output->info('从指定版本开始生成发布说明: ' . $fromTag);
|
|
||||||
$output->info('到最新tag: ' . $toTag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$output->info('从版本 ' . $fromTag . ' 生成发布说明');
|
||||||
|
$output->info('到最新tag: ' . $toTag);
|
||||||
// 获取当前版本
|
// 获取当前版本
|
||||||
$currentVersion = static::VERSION;
|
$currentVersion = static::PRODUCT_VERSION ?: static::VERSION;
|
||||||
if (!empty(static::PRODUCT_VERSION)) {
|
|
||||||
$currentVersion = static::PRODUCT_VERSION;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取从指定tag到目标tag的所有提交,包含提交哈希和提交日期
|
// 获取从指定tag到目标tag的所有提交,包含提交哈希和提交日期
|
||||||
$commits = shell_exec("git log {$fromTag}..{$toTag} --pretty=format:\"%h|%ad|%s\" --date=short");
|
$commits = shell_exec("git log {$fromTag}..{$toTag} --pretty=format:\"%h|%ad|%s\" --date=short");
|
||||||
@@ -324,7 +320,7 @@ class VersionBase extends Command
|
|||||||
$groupedCommits['其他'][] = $formatCallback($message, $commit);
|
$groupedCommits['其他'][] = $formatCallback($message, $commit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 清空空分组
|
// 清空空分组
|
||||||
foreach (array_keys($groupedCommits) as $key) {
|
foreach (array_keys($groupedCommits) as $key) {
|
||||||
if (empty($groupedCommits[$key])) {
|
if (empty($groupedCommits[$key])) {
|
||||||
|
|||||||
Reference in New Issue
Block a user