b3d9ee8255
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (push) Blocked by required conditions
Platform: moko-platform CI / Gate 5: Template Integrity (push) Blocked by required conditions
Platform: moko-platform CI / CI Summary (push) Blocked by required conditions
Generic: Repo Health / Release configuration (push) Blocked by required conditions
Generic: Repo Health / Scripts governance (push) Blocked by required conditions
Generic: Repo Health / Repository health (push) Blocked by required conditions
Generic: Repo Health / Site Health (push) Has been skipped
Generic: Repo Health / Access control (push) Successful in 2s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 36s
Wrap all CLI tools in cli/, automation/, maintenance/, deploy/, and release/ in classes extending CliFramework. Replaces manual $argv parsing with configure()/addArgument(), moves logic into run(): int, and converts fwrite(STDERR,...) to $this->log(). Two CLIApp subclasses (generate_dolibarr_version_txt, generate_joomla_update_xml) converted to extend CliFramework directly. Every script now gets free --help, --verbose, --quiet, --dry-run, --json, --no-color, banners, coloured logging, and progress bars. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
102 lines
6.9 KiB
PHP
102 lines
6.9 KiB
PHP
#!/usr/bin/env php
|
|
<?php
|
|
/* Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>
|
|
*
|
|
* This file is part of a Moko Consulting project.
|
|
*
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
*
|
|
* FILE INFORMATION
|
|
* DEFGROUP: moko-platform.CLI
|
|
* INGROUP: moko-platform
|
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
|
* PATH: /cli/create_repo.php
|
|
* BRIEF: Scaffold a new governed repository with full moko-platform baseline
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/../vendor/autoload.php';
|
|
require_once __DIR__ . '/../lib/Enterprise/CliFramework.php';
|
|
|
|
use MokoEnterprise\CliFramework;
|
|
use MokoEnterprise\Config;
|
|
use MokoEnterprise\PlatformAdapterFactory;
|
|
|
|
class CreateRepoCli extends CliFramework
|
|
{
|
|
protected function configure(): void
|
|
{
|
|
$this->setDescription('Scaffold a new governed repository with full moko-platform baseline');
|
|
$this->addArgument('--name', 'Repository name', null);
|
|
$this->addArgument('--type', 'Project type', null);
|
|
$this->addArgument('--description', 'Repository description', '');
|
|
$this->addArgument('--private', 'Create as private', false);
|
|
}
|
|
|
|
protected function run(): int
|
|
{
|
|
$name = $this->getArgument('--name'); $type = $this->getArgument('--type');
|
|
$description = $this->getArgument('--description'); $private = (bool) $this->getArgument('--private');
|
|
if (!$name || !$type) { $this->log('ERROR', "Usage: php create_repo.php --name <RepoName> --type <type> [--description \"...\"] [--private] [--dry-run]"); return 2; }
|
|
$config = Config::load(); $adapter = PlatformAdapterFactory::create($config);
|
|
$org = $config->getString($adapter->getPlatformName() . '.organization', 'mokoconsulting-tech');
|
|
$repoRoot = dirname(__DIR__, 2);
|
|
$TYPE_TO_PLATFORM = ['dolibarr' => 'crm-module', 'dolibarr-platform' => 'crm-platform', 'joomla' => 'waas-component', 'nodejs' => 'nodejs', 'terraform' => 'terraform', 'python' => 'python', 'wordpress' => 'wordpress', 'generic' => 'generic'];
|
|
$TYPE_TO_TOPICS = ['dolibarr' => ['dolibarr', 'erp', 'crm', 'php', 'mokostandards'], 'joomla' => ['joomla', 'cms', 'php', 'mokostandards'], 'nodejs' => ['nodejs', 'javascript', 'typescript', 'mokostandards'], 'terraform' => ['terraform', 'infrastructure', 'iac', 'mokostandards'], 'python' => ['python', 'mokostandards'], 'wordpress' => ['wordpress', 'php', 'cms', 'mokostandards'], 'generic' => ['mokostandards']];
|
|
$platform = $TYPE_TO_PLATFORM[$type] ?? 'generic'; $topics = $TYPE_TO_TOPICS[$type] ?? ['mokostandards'];
|
|
$platformName = $adapter->getPlatformName();
|
|
echo "Scaffolding new repository: {$org}/{$name} (on {$platformName})\n Type: {$type} (platform: {$platform})\n Visibility: " . ($private ? 'private' : 'public') . "\n";
|
|
if ($description) { echo " Description: {$description}\n"; } echo "\n";
|
|
|
|
echo "Step 1: Creating repository...\n";
|
|
if (!$this->dryRun) {
|
|
try {
|
|
$data = $adapter->createOrgRepo($org, $name, ['description' => $description ?: "Managed by moko-platform ({$type})", 'private' => $private, 'has_issues' => true, 'has_projects' => true, 'has_wiki' => false, 'auto_init' => true, 'delete_branch_on_merge' => true, 'allow_squash_merge' => true, 'allow_merge_commit' => false, 'allow_rebase_merge' => false]);
|
|
echo " Created: " . ($data['html_url'] ?? "{$org}/{$name}") . "\n";
|
|
} catch (\Exception $e) {
|
|
if (str_contains($e->getMessage(), '422') || str_contains($e->getMessage(), 'already exists')) { echo " Repository already exists -- continuing with setup\n"; }
|
|
else { $this->log('ERROR', "Failed to create repo: " . $e->getMessage()); return 1; }
|
|
}
|
|
} else { echo " (dry-run) would create {$org}/{$name}\n"; }
|
|
|
|
echo "Step 2: Setting topics...\n";
|
|
if (!$this->dryRun) { $adapter->setRepoTopics($org, $name, $topics); echo " Topics: " . implode(', ', $topics) . "\n"; }
|
|
else { echo " (dry-run) would set topics: " . implode(', ', $topics) . "\n"; }
|
|
|
|
echo "Step 3: Creating .github/.mokostandards...\n";
|
|
$mokoContent = "platform: {$platform}\nversion: 04.02.30\nmanaged: true\n";
|
|
if (!$this->dryRun) { try { $adapter->createOrUpdateFile($org, $name, '.github/.mokostandards', $mokoContent, 'chore: add .mokostandards platform config [skip ci]'); echo " .mokostandards created\n"; } catch (\Exception $e) { echo " Warning: " . $e->getMessage() . "\n"; } }
|
|
else { echo " (dry-run) would create .github/.mokostandards\n"; }
|
|
|
|
echo "Step 4: Creating README.md...\n";
|
|
$baseUrl = $platformName === 'gitea' ? $config->getString('gitea.url', 'https://git.mokoconsulting.tech') : 'https://github.com';
|
|
$repoUrl = "{$baseUrl}/{$org}/{$name}"; $standardsUrl = "{$baseUrl}/{$org}/MokoStandards";
|
|
$readmeContent = "<!--\nCopyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>\nSPDX-License-Identifier: GPL-3.0-or-later\nDEFGROUP: {$name}\nINGROUP: moko-platform\nREPO: {$repoUrl}\nPATH: /README.md\nBRIEF: {$description}\n-->\n\n# {$name}\n\n{$description}\n\n## Getting Started\n\nThis repository is governed by [moko-platform]({$standardsUrl}).\n\n## License\n\nGPL-3.0-or-later. See [LICENSE](LICENSE) for details.\n";
|
|
if (!$this->dryRun) {
|
|
$sha = null;
|
|
try { $existing = $adapter->getFileContents($org, $name, 'README.md'); $sha = $existing['sha'] ?? null; } catch (\Exception $e) { $adapter->getApiClient()->resetCircuitBreaker(); }
|
|
$adapter->createOrUpdateFile($org, $name, 'README.md', $readmeContent, 'docs: initialize README with moko-platform header [skip ci]', $sha);
|
|
echo " README.md created\n";
|
|
} else { echo " (dry-run) would create README.md\n"; }
|
|
|
|
echo "Step 5: Provisioning labels...\n";
|
|
if (!$this->dryRun) { $labelScript = "{$repoRoot}/api/maintenance/setup_labels.php"; if (file_exists($labelScript)) { $exitCode = 0; passthru("php " . escapeshellarg($labelScript) . " --org " . escapeshellarg($org) . " --repo " . escapeshellarg($name), $exitCode); } else { echo " Labels will be provisioned on next sync\n"; } }
|
|
else { echo " (dry-run) would provision standard labels\n"; }
|
|
|
|
echo "Step 6: Running initial sync...\n";
|
|
if (!$this->dryRun) { $syncScript = "{$repoRoot}/api/automation/bulk_sync.php"; if (file_exists($syncScript)) { passthru("php " . escapeshellarg($syncScript) . " --repos " . escapeshellarg($name) . " --force --yes"); } else { echo " Run manually: php automation/bulk_sync.php --repos {$name} --force --yes\n"; } }
|
|
else { echo " (dry-run) would run initial sync\n"; }
|
|
|
|
echo "Step 7: Creating Project...\n";
|
|
if (!$this->dryRun) { $projectScript = "{$repoRoot}/api/cli/create_project.php"; if (file_exists($projectScript)) { passthru("php " . escapeshellarg($projectScript) . " --repo " . escapeshellarg($name) . " --type " . escapeshellarg($type)); } else { echo " Run manually: php cli/create_project.php --repo {$name} --type {$type}\n"; } }
|
|
else { echo " (dry-run) would create Project\n"; }
|
|
|
|
echo "\n" . str_repeat('-', 50) . "\nRepository {$org}/{$name} scaffolded successfully\n URL: {$repoUrl}\n Platform: {$platform} ({$platformName})\n Next: verify the sync and merge any PRs\n";
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
$app = new CreateRepoCli();
|
|
exit($app->execute());
|