SPB Git

spb/spbgit Public MIT

SPB Git — the platform hosting itself

JavaScript 73.9% CSS 11.7% Nunjucks 11.6% Shell 2.7%
3.0 KB · 75 lines javascript
Raw Blame History
1/**2 * ─────────────────────────────────────────────3 *  SPB Git — Personal Git Platform4 * ─────────────────────────────────────────────5 *  Author  : Simon-Pierre Boucher6 *  Contact : contact@spboucher.ai7 *  File    : cli/commands/doctor.mjs8 *  Purpose : `spbgit doctor` — diagnose config, git, server, token9 *  License : MIT © Simon-Pierre Boucher10 * ─────────────────────────────────────────────11 */1213import { existsSync } from 'node:fs';14import pc from 'picocolors';15import { loadCliConfig, CONFIG_PATH } from '../lib/config.mjs';16import { git } from '../lib/git.mjs';17import { EXIT } from '../lib/api.mjs';1819export function registerDoctor(program) {20  program21    .command('doctor')22    .description('diagnose the local setup end to end')23    .action(async () => {24      let failures = 0;25      const check = (ok, label, hint) => {26        console.log(`${ok ? pc.green('✓') : pc.red('✗')} ${label}${ok || !hint ? '' : pc.dim(` — ${hint}`)}`);27        if (!ok) failures += 1;28      };2930      const config = loadCliConfig();31      check(Boolean(config), `config present (${CONFIG_PATH})`, 'run: spbgit init');3233      const gitVersion = await git(process.cwd(), ['--version']);34      check(gitVersion.ok, `git installed ${gitVersion.ok ? pc.dim(gitVersion.stdout.trim()) : ''}`, 'install git');3536      if (config) {37        check(existsSync(config.workspace), `workspace exists (${config.workspace})`, 'run: spbgit init');3839        let health = null;40        try {41          const response = await fetch(`${config.server}/healthz`);42          health = response.ok ? await response.json() : null;43        } catch {44          health = null;45        }46        check(Boolean(health), `server reachable (${config.server})`, 'check network / server process');47        if (health) {48          console.log(pc.dim(`  uptime ${health.uptimeSeconds}s · ${health.repos} repos · cache ${health.cache.files} files`));49        }5051        if (config.token) {52          let who = null;53          try {54            const response = await fetch(`${config.server}/api/v1/whoami`, {55              headers: { Authorization: `Bearer ${config.token}` },56            });57            who = response.ok ? await response.json() : null;58          } catch {59            who = null;60          }61          check(Boolean(who), `token valid${who ? pc.dim(` (label: ${who.tokenLabel})`) : ''}`, 'run: spbgit token new, then spbgit init');62        } else {63          check(false, 'token configured', 'run: spbgit init');64        }65      }6667      console.log('');68      if (failures === 0) console.log(pc.green('All checks passed — you are ready to push.'));69      else {70        console.log(pc.red(`${failures} check(s) failed.`));71        process.exit(EXIT.NETWORK);72      }73    });74}75