&1', 'cd ' . escapeshellarg(REPO_PATH) . ' && ' . GIT_BIN . ' fetch origin 2>&1', 'cd ' . escapeshellarg(REPO_PATH) . ' && ' . GIT_BIN . ' checkout ' . escapeshellarg(ALLOWED_BRANCH) . ' 2>&1', 'cd ' . escapeshellarg(REPO_PATH) . ' && ' . GIT_BIN . ' pull origin ' . escapeshellarg(ALLOWED_BRANCH) . ' 2>&1', ]; $outputAll = []; $returnCode = 0; foreach ($commands as $cmd) { $output = []; $cmdReturn = 0; exec($cmd, $output, $cmdReturn); $outputAll[] = '$ ' . $cmd; $outputAll[] = implode("\n", $output); $outputAll[] = 'exit_code=' . $cmdReturn; if ($cmdReturn !== 0) { $returnCode = $cmdReturn; break; } } $after = $data['after'] ?? ''; $pusher = $data['pusher']['login'] ?? ($data['sender']['login'] ?? 'unknown'); $logBlock = "Webhook OK | event=push | ref={$ref} | after={$after} | pusher={$pusher}\n" . implode("\n", $outputAll) . "\n---"; log_line($logBlock); if ($returnCode !== 0) { respond(500, 'Deploy failed. Revisa deploy.log'); } respond(200, 'Deploy OK');