refactor: centralize GitHub logic into GitHubService

- Create GitHubService with parseUrl, extractRepo, getBranches, getLatestCommit, getLatestRelease, hasUpdates
- Replace duplicated GitHub parsing in EmulatorConfiguration with GitHubService
- Replace fetchGitHubBranches, extractGitHubRepo, getEmulatorRemoteVersion in Commandocentrum
- Reduce code duplication across services and controllers
This commit is contained in:
root
2026-05-19 21:07:16 +02:00
parent cbe189fd96
commit 0bb35d6c8a
3 changed files with 163 additions and 132 deletions
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Services\Emulator;
use App\Services\GitHubService;
use App\Services\SettingsService;
use Illuminate\Support\Facades\Process;
@@ -134,38 +135,18 @@ trait EmulatorConfiguration
private function parseGitHubUrl(string $url): void
{
$parsed = $this->parseGithubRepoUrl($url);
$parsed = app(GitHubService::class)->parseUrl($url);
$this->githubRepo = $parsed['repo'];
$this->githubBranch = $parsed['branch'];
}
private function parseSourceRepo(string $url): void
{
$parsed = $this->parseGithubRepoUrl($url);
$parsed = app(GitHubService::class)->parseUrl($url);
$this->sourceRepo = $parsed['repo'];
$this->sourceBranch = $parsed['branch'];
}
private function parseGithubRepoUrl(string $url): array
{
if ($url === '' || $url === '0') {
return ['repo' => null, 'branch' => 'main'];
}
if (preg_match('/github\.com\/([^\/]+)\/([^\/\?#]+)/', $url, $matches)) {
$repo = $matches[1] . '/' . $matches[2];
$branch = 'main';
if (preg_match('/\/tree\/([^\/]+)/', $url, $branchMatch)) {
$branch = $branchMatch[1];
}
return ['repo' => $repo, 'branch' => $branch];
}
return ['repo' => null, 'branch' => 'main'];
}
protected function extractVersionFromFilename(string $filename): string
{
$filename = basename($filename, '.jar');