From 292a5e53abd81f7887dd7d41b0d4f149b7a1cbef Mon Sep 17 00:00:00 2001 From: hellcat <> Date: Tue, 15 Apr 2025 22:43:04 +0800 Subject: [PATCH] no message --- app/Services/TG/Hook/Mod/Git.php | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/Services/TG/Hook/Mod/Git.php b/app/Services/TG/Hook/Mod/Git.php index 676bb39..6950d70 100644 --- a/app/Services/TG/Hook/Mod/Git.php +++ b/app/Services/TG/Hook/Mod/Git.php @@ -5,6 +5,40 @@ use App\Models\Article as ModelArticle; class Git extends Base { + public function LastTime($aParam) + { + $iId = $aParam['aArg'][1]; + + $aArticle = ModelArticle::find($iId); + + $sProjectPath = env("BASE_DIR") . "github/" . $aArticle->user_name . "-" . $aArticle->project_name; + + // 进入指定目录 + if (!chdir($sProjectPath)) { + throw new \Exception("无法进入目录" . $sProjectPath); + } + + // 获取远程更新 + $fetchOutput = $this->runCommand('git fetch origin'); + if (empty($fetchOutput)) { + throw new \Exception("获取远程更新失败,输出为空。"); + } + + // 获取最后提交的时间 + $lastCommitTime = $this->runCommand('git log -1 --format=%cd origin/main'); + + // 检查是否获取到时间 + if (empty($lastCommitTime)) { + throw new \Exception("无法获取最后提交时间,可能是分支不存在或没有提交。"); + } + + // 发送最后更新时间到 Telegram + $this->oTGHttp->sendToTG("最后更新时间: " . trim($lastCommitTime)); + + $this->oHttp::response(200, 'ok'); + } + + // 没用 public function AddSshHostGithub() {