diff --git a/app/Http/Controllers/GitHubIntegrationController.php b/app/Http/Controllers/GitHubIntegrationController.php index 7891c5fe..205c2e58 100644 --- a/app/Http/Controllers/GitHubIntegrationController.php +++ b/app/Http/Controllers/GitHubIntegrationController.php @@ -200,6 +200,10 @@ protected function redirectAfterLogin(User $user, GitHubAuthType $authType, stri ->with('success', $message); } + /** + * GitHub redirects here after the app is installed and sends the installation webhook at the same + * time, so the webhook can record the installation while this request is still checking it. + */ public function handleSetup(Request $request): RedirectResponse { $installationId = (int) $request->query('installation_id'); @@ -213,21 +217,21 @@ public function handleSetup(Request $request): RedirectResponse $appService = app(GitHubAppService::class); $installation = GitHubInstallation::where('installation_id', $installationId)->first(); - if ($installation && $installation->user_id !== $user->id) { - return to_route('customer.integrations') - ->with('error', 'That GitHub App installation is already linked to another NativePHP account.'); - } - if (! $installation) { if (! $user->isUsingGitHubApp() || ! $appService->userCanAccessInstallation($user, $installationId)) { return to_route('customer.integrations') ->with('error', "We couldn't confirm that GitHub App installation belongs to your GitHub account. Please connect GitHub and try again."); } - $installation = $user->githubInstallations()->create([ - 'installation_id' => $installationId, - 'account_login' => $user->github_username ?? 'unknown', - ]); + $installation = GitHubInstallation::createOrFirst( + ['installation_id' => $installationId], + ['user_id' => $user->id, 'account_login' => $user->github_username ?? 'unknown'], + ); + } + + if ($installation->user_id !== $user->id) { + return to_route('customer.integrations') + ->with('error', 'That GitHub App installation is already linked to another NativePHP account.'); } if (! $appService->syncInstallation($installation) && ! $installation->exists) { diff --git a/resources/views/components/github-migration-banner.blade.php b/resources/views/components/github-migration-banner.blade.php index d41279bb..29283a3c 100644 --- a/resources/views/components/github-migration-banner.blade.php +++ b/resources/views/components/github-migration-banner.blade.php @@ -21,7 +21,7 @@ @if($needsMigration || $missingAccess->isNotEmpty())
- Manage which accounts and repositories the NativePHP app can access. -
+No GitHub App installations found. Install the app on your GitHub account to grant repository access.
@@ -34,7 +27,7 @@ @else