Public Access
fix: replace all hardcoded GitHub API URLs with platform adapter pattern
- cli/create_project.php: use PlatformAdapterFactory, guard GraphQL for GitHub-only - cli/joomla_release.php: use adapter for API init, platform-aware clone/upload URLs - release/generate_joomla_update_xml.php: use PlatformAdapterFactory for API init - release/generate_dolibarr_version_txt.php: same - validate/scan_drift.php: use PlatformAdapterFactory for API init - validate/check_repo_health.php: use platform-aware API base URL - validate/check_composer_deps.php: route through adapter ApiClient - maintenance/repo_inventory.php: route through adapter ApiClient, guard GraphQL - maintenance/rotate_secrets.php: route through adapter ApiClient - maintenance/update_version_from_readme.php: use PlatformAdapterFactory, rename method - lib/Common.php: set primary REPO_URL to Gitea Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
+29
-25
@@ -49,11 +49,18 @@ if (!$repoName && !$allMode) {
|
||||
exit(2);
|
||||
}
|
||||
|
||||
$token = getenv('GH_TOKEN') ?: getenv('GITHUB_TOKEN');
|
||||
if (empty($token)) {
|
||||
fwrite(STDERR, "GH_TOKEN or GITHUB_TOKEN not set\n");
|
||||
$config = \MokoEnterprise\Config::load();
|
||||
$platform = $config->getString('platform', 'gitea');
|
||||
try {
|
||||
$adapter = \MokoEnterprise\PlatformAdapterFactory::create($config);
|
||||
$api = $adapter->getApiClient();
|
||||
} catch (\Exception $e) {
|
||||
fwrite(STDERR, "Platform initialization failed: " . $e->getMessage() . "\n");
|
||||
exit(1);
|
||||
}
|
||||
$token = $platform === 'gitea'
|
||||
? $config->getString('gitea.token', '')
|
||||
: $config->getString('github.token', '');
|
||||
|
||||
$repoRoot = dirname(__DIR__, 2);
|
||||
$templatesDir = "{$repoRoot}/templates/projects";
|
||||
@@ -93,12 +100,15 @@ $TYPE_TO_TEMPLATE = [
|
||||
];
|
||||
|
||||
/**
|
||||
* Execute a GitHub GraphQL query.
|
||||
* Execute a GraphQL query (GitHub only — Gitea does not support GraphQL).
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
function graphql(string $query, array $variables, string $token): array
|
||||
function graphql(string $query, array $variables, string $token, string $platformName = 'gitea'): array
|
||||
{
|
||||
if ($platformName !== 'github') {
|
||||
return [];
|
||||
}
|
||||
$payload = json_encode(['query' => $query, 'variables' => $variables]);
|
||||
$ch = curl_init('https://api.github.com/graphql');
|
||||
curl_setopt_array($ch, [
|
||||
@@ -131,36 +141,30 @@ function graphql(string $query, array $variables, string $token): array
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute a GitHub REST API GET call.
|
||||
* Execute a REST API GET call via the platform adapter's ApiClient.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
function restGet(string $path, string $token): array
|
||||
function restGet(string $path, string $token, ?\MokoEnterprise\ApiClient $apiClient = null): array
|
||||
{
|
||||
$ch = curl_init("https://api.github.com/{$path}");
|
||||
curl_setopt_array($ch, [
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_HTTPHEADER => [
|
||||
'Authorization: token ' . $token,
|
||||
'User-Agent: MokoStandards-CreateProject',
|
||||
'Accept: application/vnd.github.v3+json',
|
||||
],
|
||||
]);
|
||||
$body = (string) curl_exec($ch);
|
||||
$status = (int) curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
curl_close($ch);
|
||||
|
||||
return $status === 200 ? (json_decode($body, true) ?? []) : [];
|
||||
if ($apiClient !== null) {
|
||||
try {
|
||||
return $apiClient->get("/{$path}");
|
||||
} catch (\Exception $e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect platform type from .mokostandards file in the repo.
|
||||
*/
|
||||
function detectPlatform(string $org, string $repo, string $token): string
|
||||
function detectPlatform(string $org, string $repo, string $token, ?\MokoEnterprise\ApiClient $apiClient = null): string
|
||||
{
|
||||
// Try .github/.mokostandards first, then root
|
||||
foreach (['.github/.mokostandards', '.mokostandards'] as $path) {
|
||||
$data = restGet("repos/{$org}/{$repo}/contents/{$path}", $token);
|
||||
// Try platform metadata dir first, then root
|
||||
foreach (['.github/.mokostandards', '.gitea/.mokostandards', '.mokostandards'] as $path) {
|
||||
$data = restGet("repos/{$org}/{$repo}/contents/{$path}", $token, $apiClient);
|
||||
if (!empty($data['content'])) {
|
||||
$content = base64_decode($data['content']);
|
||||
if (preg_match('/^platform:\s*(.+)/m', $content, $m)) {
|
||||
|
||||
Reference in New Issue
Block a user