113 lines
3.2 KiB
Batchfile
113 lines
3.2 KiB
Batchfile
@echo off
|
||
chcp 65001 >nul
|
||
setlocal enabledelayedexpansion
|
||
echo 🚀 TSP智能助手 - 快速推送
|
||
echo.
|
||
|
||
:: 检查是否有参数
|
||
if "%1"=="" (
|
||
:: 智能生成提交信息
|
||
echo 📝 分析markdown文件并生成提交信息...
|
||
|
||
:: 检查是否有markdown文件修改
|
||
set md_files=
|
||
for /f "tokens=*" %%f in ('git diff --name-only --cached 2^>nul ^| findstr /i "\.md$"') do (
|
||
set md_files=!md_files! %%f
|
||
)
|
||
for /f "tokens=*" %%f in ('git diff --name-only 2^>nul ^| findstr /i "\.md$"') do (
|
||
set md_files=!md_files! %%f
|
||
)
|
||
|
||
set commit_msg=
|
||
if not "%md_files%"=="" (
|
||
echo 📄 检测到markdown文件修改: %md_files%
|
||
|
||
:: 提取markdown文件的主要内容
|
||
set commit_title=
|
||
set commit_type=docs
|
||
|
||
:: 检查是否有修复相关内容
|
||
for %%f in (%md_files%) do (
|
||
if exist "%%f" (
|
||
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /i "修复\|解决\|问题\|错误"') do (
|
||
set commit_type=fix
|
||
set commit_title=修复问题
|
||
goto :found_fix
|
||
)
|
||
)
|
||
)
|
||
|
||
:: 检查是否有新功能相关内容
|
||
for %%f in (%md_files%) do (
|
||
if exist "%%f" (
|
||
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /i "功能\|新增\|添加\|实现"') do (
|
||
set commit_type=feat
|
||
set commit_title=新增功能
|
||
goto :found_feature
|
||
)
|
||
)
|
||
)
|
||
|
||
:: 检查是否有优化相关内容
|
||
for %%f in (%md_files%) do (
|
||
if exist "%%f" (
|
||
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /i "优化\|性能\|改进\|提升"') do (
|
||
set commit_type=perf
|
||
set commit_title=性能优化
|
||
goto :found_optimization
|
||
)
|
||
)
|
||
)
|
||
|
||
:: 提取文件标题
|
||
for %%f in (%md_files%) do (
|
||
if exist "%%f" (
|
||
for /f "tokens=*" %%l in ('type "%%f" ^| findstr /n "^#" ^| head -1') do (
|
||
set line=%%l
|
||
set line=!line:*:=!
|
||
set line=!line:# =!
|
||
set line=!line:## =!
|
||
if "!line!" neq "" (
|
||
set commit_title=!line!
|
||
goto :found_title
|
||
)
|
||
)
|
||
)
|
||
)
|
||
|
||
:found_fix
|
||
:found_feature
|
||
:found_optimization
|
||
:found_title
|
||
|
||
if "%commit_title%"=="" (
|
||
set commit_title=更新文档记录
|
||
)
|
||
|
||
:: 生成提交信息
|
||
set commit_msg=%commit_type%: %commit_title%
|
||
) else (
|
||
echo ℹ️ 没有检测到markdown文件修改
|
||
set commit_msg=feat: 快速提交 - %date% %time%
|
||
)
|
||
) else (
|
||
set commit_msg=%1
|
||
)
|
||
|
||
echo 📝 提交信息: %commit_msg%
|
||
echo.
|
||
|
||
:: 执行推送
|
||
git add . && git commit -m "%commit_msg%" && git push origin main
|
||
|
||
if %errorlevel% equ 0 (
|
||
echo.
|
||
echo ✅ 推送完成!
|
||
) else (
|
||
echo.
|
||
echo ❌ 推送失败,请检查错误信息
|
||
)
|
||
|
||
echo.
|
||
pause
|