Public Access
refactor: rename GiteaAdapter to MokoGiteaAdapter (#30)
Universal: Cascade Main → Dev / Cascade main → branches (push) Successful in 2s
Universal: Cascade Main → Dev / Cascade main → branches (push) Successful in 2s
This commit was merged in pull request #30.
This commit is contained in:
@@ -29,7 +29,7 @@ use MokoEnterprise\CliFramework;
|
|||||||
use MokoEnterprise\Config;
|
use MokoEnterprise\Config;
|
||||||
use MokoEnterprise\PlatformAdapterFactory;
|
use MokoEnterprise\PlatformAdapterFactory;
|
||||||
use MokoEnterprise\GitHubAdapter;
|
use MokoEnterprise\GitHubAdapter;
|
||||||
use MokoEnterprise\GiteaAdapter;
|
use MokoEnterprise\MokoGiteaAdapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gitea Migration Script
|
* Gitea Migration Script
|
||||||
@@ -42,7 +42,7 @@ use MokoEnterprise\GiteaAdapter;
|
|||||||
class MigrateToGitea extends CliFramework
|
class MigrateToGitea extends CliFramework
|
||||||
{
|
{
|
||||||
private ?GitHubAdapter $github = null;
|
private ?GitHubAdapter $github = null;
|
||||||
private ?GiteaAdapter $gitea = null;
|
private ?MokoGiteaAdapter $gitea = null;
|
||||||
private ?CheckpointManager $checkpoints = null;
|
private ?CheckpointManager $checkpoints = null;
|
||||||
|
|
||||||
protected function configure(): void
|
protected function configure(): void
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ namespace MokoEnterprise;
|
|||||||
* Git Platform Adapter Interface
|
* Git Platform Adapter Interface
|
||||||
*
|
*
|
||||||
* Defines all platform operations required by MokoStandards automation.
|
* Defines all platform operations required by MokoStandards automation.
|
||||||
* Implementations exist for GitHub (GitHubAdapter) and Gitea (GiteaAdapter),
|
* Implementations exist for GitHub (GitHubAdapter) and Gitea (MokoGiteaAdapter),
|
||||||
* allowing scripts to work against either platform transparently.
|
* allowing scripts to work against either platform transparently.
|
||||||
*
|
*
|
||||||
* @package MokoStandards\Enterprise
|
* @package MokoStandards\Enterprise
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* DEFGROUP: MokoStandards.Enterprise.Platform
|
* DEFGROUP: MokoStandards.Enterprise.Platform
|
||||||
* INGROUP: MokoStandards.Enterprise
|
* INGROUP: MokoStandards.Enterprise
|
||||||
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
* REPO: https://git.mokoconsulting.tech/MokoConsulting/moko-platform
|
||||||
* PATH: /lib/Enterprise/GiteaAdapter.php
|
* PATH: /lib/Enterprise/MokoGiteaAdapter.php
|
||||||
* BRIEF: Gitea implementation of GitPlatformAdapter
|
* BRIEF: Gitea implementation of GitPlatformAdapter
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ use RuntimeException;
|
|||||||
* @package MokoStandards\Enterprise
|
* @package MokoStandards\Enterprise
|
||||||
* @version 04.06.10
|
* @version 04.06.10
|
||||||
*/
|
*/
|
||||||
class GiteaAdapter implements GitPlatformAdapter
|
class MokoGiteaAdapter implements GitPlatformAdapter
|
||||||
{
|
{
|
||||||
private ApiClient $apiClient;
|
private ApiClient $apiClient;
|
||||||
private string $baseUrl;
|
private string $baseUrl;
|
||||||
@@ -51,7 +51,7 @@ class PlatformAdapterFactory
|
|||||||
|
|
||||||
return match ($platform) {
|
return match ($platform) {
|
||||||
'github' => self::createGitHubAdapter($config),
|
'github' => self::createGitHubAdapter($config),
|
||||||
'gitea' => self::createGiteaAdapter($config),
|
'gitea' => self::createMokoGiteaAdapter($config),
|
||||||
default => throw new RuntimeException("Unsupported git platform: {$platform}. Use 'github' or 'gitea'."),
|
default => throw new RuntimeException("Unsupported git platform: {$platform}. Use 'github' or 'gitea'."),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -84,13 +84,13 @@ class PlatformAdapterFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a GiteaAdapter with configured ApiClient.
|
* Create a MokoGiteaAdapter with configured ApiClient.
|
||||||
*
|
*
|
||||||
* @param Config $config Configuration instance
|
* @param Config $config Configuration instance
|
||||||
* @return GiteaAdapter Configured Gitea adapter
|
* @return MokoGiteaAdapter Configured Gitea adapter
|
||||||
* @throws RuntimeException If Gitea token is not available
|
* @throws RuntimeException If Gitea token is not available
|
||||||
*/
|
*/
|
||||||
private static function createGiteaAdapter(Config $config): GiteaAdapter
|
private static function createMokoGiteaAdapter(Config $config): MokoGiteaAdapter
|
||||||
{
|
{
|
||||||
$token = $config->getString('gitea.token', '');
|
$token = $config->getString('gitea.token', '');
|
||||||
if (empty($token)) {
|
if (empty($token)) {
|
||||||
@@ -110,21 +110,21 @@ class PlatformAdapterFactory
|
|||||||
authScheme: 'token'
|
authScheme: 'token'
|
||||||
);
|
);
|
||||||
|
|
||||||
return new GiteaAdapter($apiClient, $apiBaseUrl);
|
return new MokoGiteaAdapter($apiClient, $apiBaseUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create adapters for both platforms (useful during migration).
|
* Create adapters for both platforms (useful during migration).
|
||||||
*
|
*
|
||||||
* @param Config $config Configuration instance
|
* @param Config $config Configuration instance
|
||||||
* @return array{github: GitHubAdapter, gitea: GiteaAdapter} Both adapters
|
* @return array{github: GitHubAdapter, gitea: MokoGiteaAdapter} Both adapters
|
||||||
* @throws RuntimeException If either token is missing
|
* @throws RuntimeException If either token is missing
|
||||||
*/
|
*/
|
||||||
public static function createBoth(Config $config): array
|
public static function createBoth(Config $config): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'github' => self::createGitHubAdapter($config),
|
'github' => self::createGitHubAdapter($config),
|
||||||
'gitea' => self::createGiteaAdapter($config),
|
'gitea' => self::createMokoGiteaAdapter($config),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ class RepositorySynchronizer
|
|||||||
?GitPlatformAdapter $adapter = null
|
?GitPlatformAdapter $adapter = null
|
||||||
) {
|
) {
|
||||||
$this->apiClient = $apiClient;
|
$this->apiClient = $apiClient;
|
||||||
$this->adapter = $adapter ?? new GiteaAdapter($apiClient);
|
$this->adapter = $adapter ?? new MokoGiteaAdapter($apiClient);
|
||||||
$this->logger = $logger;
|
$this->logger = $logger;
|
||||||
$this->metrics = $metrics;
|
$this->metrics = $metrics;
|
||||||
$this->checkpoints = $checkpoints ?? new CheckpointManager('.checkpoints');
|
$this->checkpoints = $checkpoints ?? new CheckpointManager('.checkpoints');
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use MokoEnterprise\ApiClient;
|
|||||||
use MokoEnterprise\Config;
|
use MokoEnterprise\Config;
|
||||||
use MokoEnterprise\GitPlatformAdapter;
|
use MokoEnterprise\GitPlatformAdapter;
|
||||||
use MokoEnterprise\GitHubAdapter;
|
use MokoEnterprise\GitHubAdapter;
|
||||||
use MokoEnterprise\GiteaAdapter;
|
use MokoEnterprise\MokoGiteaAdapter;
|
||||||
use MokoEnterprise\PlatformAdapterFactory;
|
use MokoEnterprise\PlatformAdapterFactory;
|
||||||
|
|
||||||
echo "Testing GitPlatformAdapter Interface Compliance\n";
|
echo "Testing GitPlatformAdapter Interface Compliance\n";
|
||||||
@@ -58,8 +58,8 @@ assert_true($ghAdapter->getWorkflowDir() === '.github/workflows', 'getWorkflowDi
|
|||||||
assert_true($ghAdapter->getApiClient() === $ghClient, 'getApiClient() returns injected client');
|
assert_true($ghAdapter->getApiClient() === $ghClient, 'getApiClient() returns injected client');
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
|
||||||
// ── Test 2: GiteaAdapter implements GitPlatformAdapter ──────────────────
|
// ── Test 2: MokoGiteaAdapter implements GitPlatformAdapter ──────────────────
|
||||||
echo "2. Testing GiteaAdapter interface compliance...\n";
|
echo "2. Testing MokoGiteaAdapter interface compliance...\n";
|
||||||
|
|
||||||
$giteaClient = new ApiClient(
|
$giteaClient = new ApiClient(
|
||||||
baseUrl: 'https://git.mokoconsulting.tech/api/v1',
|
baseUrl: 'https://git.mokoconsulting.tech/api/v1',
|
||||||
@@ -67,9 +67,9 @@ $giteaClient = new ApiClient(
|
|||||||
enableCaching: false,
|
enableCaching: false,
|
||||||
authScheme: 'token'
|
authScheme: 'token'
|
||||||
);
|
);
|
||||||
$giteaAdapter = new GiteaAdapter($giteaClient);
|
$giteaAdapter = new MokoGiteaAdapter($giteaClient);
|
||||||
|
|
||||||
assert_true($giteaAdapter instanceof GitPlatformAdapter, 'GiteaAdapter implements GitPlatformAdapter');
|
assert_true($giteaAdapter instanceof GitPlatformAdapter, 'MokoGiteaAdapter implements GitPlatformAdapter');
|
||||||
assert_true($giteaAdapter->getPlatformName() === 'gitea', 'getPlatformName() returns "gitea"');
|
assert_true($giteaAdapter->getPlatformName() === 'gitea', 'getPlatformName() returns "gitea"');
|
||||||
assert_true($giteaAdapter->getBaseUrl() === 'https://git.mokoconsulting.tech/api/v1', 'getBaseUrl() returns Gitea API URL');
|
assert_true($giteaAdapter->getBaseUrl() === 'https://git.mokoconsulting.tech/api/v1', 'getBaseUrl() returns Gitea API URL');
|
||||||
assert_true($giteaAdapter->getWorkflowDir() === '.mokogitea/workflows', 'getWorkflowDir() returns .gitea/workflows');
|
assert_true($giteaAdapter->getWorkflowDir() === '.mokogitea/workflows', 'getWorkflowDir() returns .gitea/workflows');
|
||||||
@@ -125,10 +125,10 @@ try {
|
|||||||
$config->set('gitea.token', 'test-gitea-token');
|
$config->set('gitea.token', 'test-gitea-token');
|
||||||
try {
|
try {
|
||||||
$adapter = PlatformAdapterFactory::create($config, 'gitea');
|
$adapter = PlatformAdapterFactory::create($config, 'gitea');
|
||||||
assert_true($adapter instanceof GiteaAdapter, 'Factory creates GiteaAdapter for platform=gitea');
|
assert_true($adapter instanceof MokoGiteaAdapter, 'Factory creates MokoGiteaAdapter for platform=gitea');
|
||||||
assert_true($adapter->getPlatformName() === 'gitea', 'Created adapter identifies as gitea');
|
assert_true($adapter->getPlatformName() === 'gitea', 'Created adapter identifies as gitea');
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
assert_true(false, 'Factory creates GiteaAdapter: ' . $e->getMessage());
|
assert_true(false, 'Factory creates MokoGiteaAdapter: ' . $e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test invalid platform
|
// Test invalid platform
|
||||||
@@ -185,9 +185,9 @@ try {
|
|||||||
assert_true(true, 'GitHubAdapter.migrateRepository() throws RuntimeException');
|
assert_true(true, 'GitHubAdapter.migrateRepository() throws RuntimeException');
|
||||||
}
|
}
|
||||||
|
|
||||||
// GiteaAdapter.migrateRepository() should NOT throw (it calls the API)
|
// MokoGiteaAdapter.migrateRepository() should NOT throw (it calls the API)
|
||||||
// We can't test it without a real server, but verify the method exists
|
// We can't test it without a real server, but verify the method exists
|
||||||
assert_true(method_exists($giteaAdapter, 'migrateRepository'), 'GiteaAdapter.migrateRepository() exists');
|
assert_true(method_exists($giteaAdapter, 'migrateRepository'), 'MokoGiteaAdapter.migrateRepository() exists');
|
||||||
echo "\n";
|
echo "\n";
|
||||||
|
|
||||||
// ── Summary ─────────────────────────────────────────────────────────────
|
// ── Summary ─────────────────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user