66e728b078
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.1) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.2) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 2: Unit Tests (8.3) (push) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 3: Self-Health Check (push) Blocked by required conditions
Platform: moko-platform CI / Gate 5: Template Integrity (pull_request) Blocked by required conditions
Platform: moko-platform CI / Gate 4: Governance (push) Blocked by required conditions
Platform: moko-platform CI / CI Summary (pull_request) 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
Universal: PR Check / Build RC Package (pull_request) Blocked by required conditions
Generic: Repo Health / Release configuration (pull_request) Blocked by required conditions
Generic: Repo Health / Scripts governance (pull_request) Blocked by required conditions
Generic: Repo Health / Repository health (pull_request) Blocked by required conditions
Generic: Repo Health / Access control (push) Successful in 18s
Generic: Repo Health / Site Health (push) Has been skipped
Universal: PR Check / Branch Policy (pull_request) Successful in 3s
Universal: Auto Version Bump / Version Bump (push) Failing after 27s
Universal: Secret Scanning / Gitleaks Secret Scan (pull_request) Successful in 28s
Universal: PR Check / Validate PR (pull_request) Failing after 6s
Generic: Repo Health / Site Health (pull_request) Has been skipped
Generic: Repo Health / Access control (pull_request) Successful in 3s
Platform: moko-platform CI / Gate 1: Code Quality (pull_request) Failing after 1m7s
Platform: moko-platform CI / Gate 1: Code Quality (push) Failing after 1m7s
Auto-fixed 5006 tab-indent and line-ending errors via phpcbf, then manually broke 100 lines exceeding 150-char limit. All 74 files in cli/, automation/, maintenance/, deploy/ now pass PHPCS PSR-12 clean. Authored-by: Moko Consulting Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
228 lines
9.1 KiB
PHP
228 lines
9.1 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();
|
|
$vis = $private ? 'private' : 'public';
|
|
echo "Scaffolding new repository: {$org}/{$name}"
|
|
. " (on {$platformName})\n"
|
|
. " Type: {$type} (platform: {$platform})\n"
|
|
. " Visibility: {$vis}\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 = "<!--\n"
|
|
. "Copyright (C) 2026 Moko Consulting <hello@mokoconsulting.tech>\n"
|
|
. "SPDX-License-Identifier: GPL-3.0-or-later\n"
|
|
. "DEFGROUP: {$name}\n"
|
|
. "INGROUP: moko-platform\n"
|
|
. "REPO: {$repoUrl}\n"
|
|
. "PATH: /README.md\n"
|
|
. "BRIEF: {$description}\n"
|
|
. "-->\n\n"
|
|
. "# {$name}\n\n"
|
|
. "{$description}\n\n"
|
|
. "## Getting Started\n\n"
|
|
. "This repository is governed by"
|
|
. " [moko-platform]({$standardsUrl}).\n\n"
|
|
. "## License\n\n"
|
|
. "GPL-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) . "\n"
|
|
. "Repository {$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());
|