oTGHttp->sendToTG($sMsg); $this->oHttp::response(200, 'ok'); } // /Git#PullR 3 public function PullR($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); } // 获取远程更新 $this->runCommand('git fetch origin'); // 硬重置到远程主分支 $this->runCommand('git reset --hard origin/main'); $this->oTGHttp->sendToTG("操作完成:已重置到远程主分支"); $this->oHttp::response(200, 'ok'); } private function runCommand($command) { $output = []; $returnVar = 0; exec($command, $output, $returnVar); if ($returnVar !== 0) { // 将输出数组转换为 JSON 格式 $jsonOutput = json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE); $errorMessage = "命令失败: $command\n" . $jsonOutput . "\n"; throw new \Exception($errorMessage); } } }