SPB Git

spb/spbgit Public MIT

SPB Git — the platform hosting itself

JavaScript 73.9% CSS 11.7% Nunjucks 11.6% Shell 2.7%
2.4 KB · 61 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/info.mjs8 *  Purpose : `spbgit info <name>` — server-side repository details9 *  License : MIT © Simon-Pierre Boucher10 * ─────────────────────────────────────────────11 */1213import pc from 'picocolors';14import { requireCliConfig } from '../lib/config.mjs';15import { api } from '../lib/api.mjs';16import { printTable } from '../lib/ui.mjs';17import { ago } from './list.mjs';1819function humanBytes(bytes) {20  const units = ['B', 'KB', 'MB', 'GB'];21  let value = Number(bytes) || 0;22  let i = 0;23  while (value >= 1024 && i < units.length - 1) {24    value /= 1024;25    i += 1;26  }27  return `${i === 0 ? value : value.toFixed(1)} ${units[i]}`;28}2930export function registerInfo(program) {31  program32    .command('info <name>')33    .description('show server-side details of a repository')34    .option('--json', 'machine-readable output')35    .action(async (name, opts) => {36      const config = requireCliConfig();37      const repo = await api(config, 'GET', `/api/v1/repos/${encodeURIComponent(name)}`, undefined, { auth: false });38      if (opts.json) {39        console.log(JSON.stringify(repo, null, 2));40        return;41      }42      console.log(`\n${pc.bold(repo.name)} ${repo.pinned ? pc.yellow('★') : ''}`);43      if (repo.description) console.log(pc.dim(repo.description));44      console.log('');45      printTable([46        [pc.bold('URL'), repo.url],47        [pc.bold('Clone'), repo.cloneUrl],48        [pc.bold('Default branch'), repo.defaultBranch],49        [pc.bold('Commits'), String(repo.commitCount)],50        [pc.bold('Branches'), String(repo.branchCount)],51        [pc.bold('Tags'), String(repo.tagCount)],52        [pc.bold('Size'), humanBytes(repo.sizeBytes)],53        [pc.bold('Language'), repo.topLanguage ?? '—'],54        [pc.bold('License'), repo.license ?? '—'],55        [pc.bold('Topics'), repo.topics.join(', ') || '—'],56        [pc.bold('Last push'), ago(repo.lastPush)],57        [pc.bold('Clones'), String(repo.cloneCount ?? 0)],58      ]);59    });60}61