An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
fix(github): sync app slug before generating installation path
Andras Bacsai507a8afa2001
diff --git a/app/Livewire/Source/Github/Change.php b/app/Livewire/Source/Github/Change.phpindex 17835258be..682333aa6b 100644--- a/app/Livewire/Source/Github/Change.php+++ b/app/Livewire/Source/Github/Change.php@@ -204,6 +204,8 @@ class Change extends Componentreturn;}+ syncGithubAppName($this->github_app);+GithubAppPermissionJob::dispatchSync($this->github_app);$this->github_app->refresh()->makeVisible('client_secret')->makeVisible('webhook_secret');$this->syncData(false);diff --git a/bootstrap/helpers/github.php b/bootstrap/helpers/github.phpindex a2feb3360f..978e9ddaeb 100644--- a/bootstrap/helpers/github.php+++ b/bootstrap/helpers/github.php@@ -192,8 +192,6 @@ function syncGithubAppName(GithubApp $source, bool $throw = false): ?stringfunction getInstallationPath(GithubApp $source): string{- syncGithubAppName($source);-$name = str(Str::kebab($source->name));$baseUrl = rtrim($source->html_url, '/');$host = parse_url($source->html_url, PHP_URL_HOST);diff --git a/tests/Feature/GithubSourceChangeTest.php b/tests/Feature/GithubSourceChangeTest.phpindex 0b80300505..70d4e101d3 100644--- a/tests/Feature/GithubSourceChangeTest.php+++ b/tests/Feature/GithubSourceChangeTest.php@@ -171,9 +171,42 @@ describe('GitHub Source Change Component', function () {]);});- test('installation path synchronizes github app slug before generating the url', function () {+ test('installation path is pure and never calls github or mutates the app', function () {+ Http::fake();++ $privateKey = PrivateKey::create([+ 'name' => 'github-app-local-name',+ 'private_key' => validPrivateKey(),+ 'team_id' => $this->team->id,+ 'is_git_related' => true,+ ]);++ $githubApp = GithubApp::create([+ 'name' => 'Local Display Name',+ 'organization' => 'acme-enterprise',+ 'api_url' => 'https://api.github.com',+ 'html_url' => 'https://octocorp.ghe.com',+ 'custom_user' => 'git',+ 'custom_port' => 22,+ 'app_id' => 12345,+ 'private_key_id' => $privateKey->id,+ 'team_id' => $this->team->id,+ 'is_system_wide' => false,+ ]);++ $installationUrl = getInstallationPath($githubApp);++ Http::assertNothingSent();++ expect($installationUrl)->toStartWith('https://octocorp.ghe.com/apps/acme-enterprise/local-display-name/installations/new?')+ ->and($githubApp->refresh()->name)->toBe('Local Display Name')+ ->and($privateKey->refresh()->name)->toBe('github-app-local-name');+ });++ test('syncGithubAppName persists the github slug and renames the private key', function () {Http::fake([- 'https://api.github.com/app' => Http::response(['slug' => 'actual-github-slug']),+ '*/app' => Http::response(['slug' => 'actual-github-slug']),+ '*/zen' => Http::response('Keep it logically awesome.'),]);$privateKey = PrivateKey::create([@@ -196,9 +229,9 @@ describe('GitHub Source Change Component', function () {'is_system_wide' => false,]);- $installationUrl = getInstallationPath($githubApp);+ $appSlug = syncGithubAppName($githubApp, true);- expect($installationUrl)->toStartWith('https://octocorp.ghe.com/apps/acme-enterprise/actual-github-slug/installations/new?')+ expect($appSlug)->toBe('actual-github-slug')->and($githubApp->refresh()->name)->toBe('actual-github-slug')->and($privateKey->refresh()->name)->toBe('github-app-actual-github-slug');});