From e8c37ccdbd7eb4d186c6cec75a8a882a8dbb26c9 Mon Sep 17 00:00:00 2001 From: Andrew Valleteau Date: Sat, 27 Sep 2025 06:59:47 +0200 Subject: [PATCH] fix(studio): refetch GitHub repositories after new install (#39021) * fix(studio): add refetch after github pop-up close * fix: github.ts * fix: add delay * chore: increase to 2s * chore: remove debug logs --- .../GitHubIntegrationConnectionForm.tsx | 41 ++++++++++++++----- .../integrations/github-repositories-query.ts | 3 +- apps/studio/lib/github.ts | 23 +++++++++-- 3 files changed, 51 insertions(+), 16 deletions(-) diff --git a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx index 5c69fa0dc3..152da94ad0 100644 --- a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx +++ b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx @@ -47,6 +47,7 @@ import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout' const GITHUB_ICON = ( + GitHub icon ({ + const { + data: githubReposData, + isLoading: isLoadingGitHubRepos, + refetch: refetchGitHubRepositories, + } = useGitHubRepositoriesQuery({ enabled: Boolean(gitHubAuthorization), }) + const refetchGitHubAuthorizationAndRepositories = () => { + setTimeout(() => { + refetchGitHubAuthorization() + refetchGitHubRepositories() + }, 2000) // 2 second to delay to let github authorization and repositories to be updated + } + const { mutate: updateBranch } = useBranchUpdateMutation({ onSuccess: () => { toast.success('Production branch settings successfully updated') @@ -130,7 +141,7 @@ const GitHubIntegrationConnectionForm = ({ const githubRepos = useMemo( () => - githubReposData?.map((repo: any) => ({ + githubReposData?.map((repo) => ({ id: repo.id.toString(), name: repo.name, installation_id: repo.installation_id, @@ -161,7 +172,7 @@ const GitHubIntegrationConnectionForm = ({ repositoryId: Number(repositoryId), branchName: val.branchName, }) - } catch (error) { + } catch { const selectedRepo = githubRepos.find((repo) => repo.id === repositoryId) const repoName = selectedRepo?.name || connection?.repository.name || 'selected repository' @@ -337,11 +348,11 @@ const GitHubIntegrationConnectionForm = ({ const data = githubSettingsForm.getValues() const selectedRepo = githubRepos.find((repo) => repo.id === data.repositoryId) - if (!selectedRepo || !connection) return + if (!selectedRepo || !connection || !selectedOrganization?.id) return try { await deleteConnection({ - organizationId: selectedOrganization!.id, + organizationId: selectedOrganization.id, connectionId: connection.id, }) @@ -390,7 +401,10 @@ const GitHubIntegrationConnectionForm = ({