Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Update GH integration in project settings (#44008)

Joshen Lime310c24199ce
diff --git a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx
index 1d9d98afe9d..2d1208afb45 100644
--- a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx
+++ b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GitHubIntegrationConnectionForm.tsx
@@ -1,6 +1,6 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { IS_PLATFORM } from 'common'
+import { InlineLink } from 'components/ui/InlineLink'
import { useBranchCreateMutation } from 'data/branches/branch-create-mutation'
import { useBranchUpdateMutation } from 'data/branches/branch-update-mutation'
import { useBranchesQuery } from 'data/branches/branches-query'
@@ -11,6 +11,7 @@ import { useGitHubConnectionDeleteMutation } from 'data/integrations/github-conn
import { useGitHubConnectionUpdateMutation } from 'data/integrations/github-connection-update-mutation'
import { useGitHubRepositoriesQuery } from 'data/integrations/github-repositories-query'
import type { GitHubConnection } from 'data/integrations/integrations.types'
+import { AnimatePresence, motion } from 'framer-motion'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
@@ -22,9 +23,6 @@ import { useEffect, useMemo, useState } from 'react'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import {
- Alert_Shadcn_,
- AlertDescription_Shadcn_,
- AlertTitle_Shadcn_,
Button,
Card,
CardContent,
@@ -46,10 +44,12 @@ import {
PopoverTrigger_Shadcn_,
Switch,
} from 'ui'
-import { InlineLink } from 'components/ui/InlineLink'
+import { Admonition } from 'ui-patterns'
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import * as z from 'zod'
+
+import { UpgradeToPro } from '@/components/ui/UpgradeToPro'
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
const GITHUB_ICON = (
@@ -65,12 +65,10 @@ const GITHUB_ICON = (
)
interface GitHubIntegrationConnectionFormProps {
- disabled?: boolean
connection?: GitHubConnection
}
-const GitHubIntegrationConnectionForm = ({
- disabled = false,
+export const GitHubIntegrationConnectionForm = ({
connection,
}: GitHubIntegrationConnectionFormProps) => {
const { data: selectedProject } = useSelectedProjectQuery()
@@ -82,8 +80,8 @@ const GitHubIntegrationConnectionForm = ({
const { hasAccess: hasAccessToGitHubIntegration, isLoading: isLoadingEntitlements } =
useCheckEntitlements('integrations.github_connections')
- const promptProPlanUpgrade =
- IS_PLATFORM && !isLoadingEntitlements && !hasAccessToGitHubIntegration
+
+ const { hasAccess: hasAccessToBranching } = useCheckEntitlements('branching_limit')
const { can: canUpdateGitHubConnection } = useAsyncCheckPermissions(
PermissionAction.UPDATE,
@@ -460,7 +458,7 @@ const GitHubIntegrationConnectionForm = ({
<Button
type="default"
className="justify-start h-[34px] w-full"
- disabled={disabled || isLoadingGitHubRepos}
+ disabled={isLoadingGitHubRepos}
loading={isLoadingGitHubRepos}
icon={
<div className="bg-black shadow rounded p-1 w-6 h-6 flex justify-center items-center">
@@ -553,213 +551,244 @@ const GitHubIntegrationConnectionForm = ({
)}
/>
</CardContent>
- <CardContent className={cn(!currentRepositoryId && 'opacity-25 pointer-events-none')}>
- <FormField_Shadcn_
- control={githubSettingsForm.control}
- name="supabaseDirectory"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label="Working directory"
- description="Path to working directory with your supabase folder"
- >
- <FormControl_Shadcn_>
- <Input_Shadcn_
- {...field}
- placeholder="supabase"
- autoComplete="off"
- disabled={disabled || !canUpdateGitHubConnection}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </CardContent>
- <CardContent className={cn(!currentRepositoryId && 'opacity-25 pointer-events-none')}>
- {/* Production Branch Sync Section */}
- <div className="space-y-4">
- <FormField_Shadcn_
- control={githubSettingsForm.control}
- name="enableProductionSync"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label="Deploy to production"
- description="Deploy changes to production on push including PR merges"
- >
- <FormControl_Shadcn_>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- disabled={disabled || !canUpdateGitHubConnection}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
-
- <div
- className={cn(
- 'space-y-4 pl-6 border-l',
- (!enableProductionSync || disabled) && 'opacity-25 pointer-events-none'
- )}
+
+ <AnimatePresence>
+ {!!currentRepositoryId && (
+ <motion.div
+ initial={{ opacity: 0, y: -16 }}
+ animate={{ opacity: 1, y: 0 }}
+ exit={{ opacity: 0, y: -16 }}
>
- <FormField_Shadcn_
- control={githubSettingsForm.control}
- name="branchName"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label="Production branch name"
- description="The GitHub branch to sync with your production database (e.g., main, master)"
- >
- <div className="relative w-full">
+ <CardContent>
+ <FormField_Shadcn_
+ control={githubSettingsForm.control}
+ name="supabaseDirectory"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Working directory"
+ description="Path to working directory with your supabase folder"
+ >
<FormControl_Shadcn_>
<Input_Shadcn_
{...field}
+ placeholder="supabase"
autoComplete="off"
- disabled={
- disabled || !canUpdateGitHubConnection || !enableProductionSync
- }
+ disabled={!canUpdateGitHubConnection}
/>
</FormControl_Shadcn_>
- <div className="absolute top-2.5 right-3 flex items-center gap-2">
- {isCheckingBranch && <Loader2 size={14} className="animate-spin" />}
- </div>
- </div>
- </FormItemLayout>
- )}
- />
- </div>
- </div>
- </CardContent>
- <CardContent className={cn(!currentRepositoryId && 'opacity-25 pointer-events-none')}>
- <Alert_Shadcn_ variant="warning" className="mb-4">
- <AlertTitle_Shadcn_>Branching and billing</AlertTitle_Shadcn_>
- <AlertDescription_Shadcn_>
- Branching Compute is not covered by your organization&apos;s Spend Cap. Costs
- should be closely monitored, as they may be incurred.{' '}
- <InlineLink
- href={`${DOCS_URL}/guides/platform/cost-control#usage-items-not-covered-by-the-spend-cap`}
- >
- Learn more
- </InlineLink>
- </AlertDescription_Shadcn_>
- </Alert_Shadcn_>
- {/* Automatic Branching Section */}
- <div className="space-y-4">
- <FormField_Shadcn_
- control={githubSettingsForm.control}
- name="new_branch_per_pr"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label="Automatic branching"
- description="Create preview branches for every pull request"
- >
- <FormControl_Shadcn_>
- <Switch
- checked={field.value}
- onCheckedChange={field.onChange}
- disabled={disabled || !canCreateGitHubConnection}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
-
- <div
- className={cn(
- 'space-y-4 pl-6 border-l',
- (!newBranchPerPr || disabled) && 'opacity-25 pointer-events-none'
- )}
- >
- <FormField_Shadcn_
- control={githubSettingsForm.control}
- name="branchLimit"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label="Branch limit"
- description="Maximum number of preview branches"
+ </FormItemLayout>
+ )}
+ />
+ </CardContent>
+ <CardContent>
+ {/* Production Branch Sync Section */}
+ <div className="space-y-4">
+ <FormField_Shadcn_
+ control={githubSettingsForm.control}
+ name="enableProductionSync"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Deploy to production"
+ description="Deploy changes to production on push including PR merges"
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ checked={field.value}
+ onCheckedChange={field.onChange}
+ disabled={!canUpdateGitHubConnection}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <div
+ className={cn(
+ 'space-y-4 pl-6 border-l',
+ !enableProductionSync && 'opacity-25 pointer-events-none'
+ )}
>
- <FormControl_Shadcn_>
- <Input_Shadcn_
- {...field}
- type="number"
- autoComplete="off"
- disabled={!newBranchPerPr || disabled || !canUpdateGitHubConnection}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
+ <FormField_Shadcn_
+ control={githubSettingsForm.control}
+ name="branchName"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Production branch name"
+ description="The GitHub branch to sync with your production database (e.g., main, master)"
+ >
+ <div className="relative w-full">
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ autoComplete="off"
+ disabled={!canUpdateGitHubConnection || !enableProductionSync}
+ />
+ </FormControl_Shadcn_>
+ <div className="absolute top-2.5 right-3 flex items-center gap-2">
+ {isCheckingBranch && (
+ <Loader2 size={14} className="animate-spin" />
+ )}
+ </div>
+ </div>
+ </FormItemLayout>
+ )}
+ />
+ </div>
+ </div>
+ </CardContent>
+ <CardContent>
+ {hasAccessToBranching ? (
+ <Admonition type="warning" title="Branching and billing" className="mb-4">
+ Branching Compute is not covered by your organization&apos;s Spend Cap.
+ Costs should be closely monitored, as they may be incurred.{' '}
+ <InlineLink
+ href={`${DOCS_URL}/guides/platform/cost-control#usage-items-not-covered-by-the-spend-cap`}
+ >
+ Learn more
+ </InlineLink>
+ </Admonition>
+ ) : (
+ <UpgradeToPro
+ className="mb-4"
+ layout="vertical"
+ source="projectIntegrations"
+ featureProposition="automatically create preview branches from pull requests"
+ primaryText="Branching with GitHub integration"
+ secondaryText="Upgrade to the Pro Plan to enable branching and automatically create preview branches for every pull request"
+ docsUrl={`${DOCS_URL}/guides/deployment/branching`}
+ />
)}
- />
-
- <FormField_Shadcn_
- control={githubSettingsForm.control}
- name="supabaseChangesOnly"
- render={({ field }) => (
- <FormItemLayout
- layout="flex-row-reverse"
- label="Supabase changes only"
- description="Only create branches when Supabase files change"
+
+ {/* Automatic Branching Section */}
+ <div className="space-y-4">
+ <FormField_Shadcn_
+ disabled={!hasAccessToBranching}
+ control={githubSettingsForm.control}
+ name="new_branch_per_pr"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Automatic branching"
+ className={cn(!hasAccessToBranching && 'opacity-25')}
+ description="Create preview branches for every pull request"
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ checked={!hasAccessToBranching ? false : field.value}
+ onCheckedChange={field.onChange}
+ disabled={!hasAccessToBranching || !canCreateGitHubConnection}
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <div
+ className={cn(
+ 'space-y-4 pl-6 border-l',
+ (!hasAccessToBranching || !newBranchPerPr) &&
+ 'opacity-25 pointer-events-none'
+ )}
>
- <FormControl_Shadcn_>
- <Switch
- checked={field.value}
- onCheckedChange={(val) => field.onChange(val)}
- disabled={!newBranchPerPr || disabled || !canUpdateGitHubConnection}
- />
- </FormControl_Shadcn_>
- </FormItemLayout>
- )}
- />
- </div>
- </div>
- </CardContent>
- <CardFooter className="flex justify-between items-center">
- <div>
- {connection && (
- <Button
- type="outline"
- onClick={handleRemoveIntegration}
- disabled={isDeletingConnection}
- loading={isDeletingConnection}
- >
- Disable integration
- </Button>
- )}
- </div>
- <div className="flex space-x-2">
- {githubSettingsForm.formState.isDirty && (
- <Button
- type="default"
- onClick={() => {
- githubSettingsForm.reset()
- }}
- disabled={disabled || !canUpdateGitHubConnection}
- >
- Cancel
- </Button>
- )}
- <Button
- type={promptProPlanUpgrade ? 'default' : 'primary'}
- htmlType="submit"
- disabled={
- disabled ||
- (!connection && !canCreateGitHubConnection) ||
- (connection && !canUpdateGitHubConnection) ||
- isCheckingBranch ||
- isLoading ||
- (!connection && !githubSettingsForm.getValues().repositoryId) ||
- (connection && !githubSettingsForm.formState.isDirty)
- }
- loading={isCheckingBranch || isLoading}
- >
- {connection ? 'Save changes' : 'Enable integration'}
- </Button>
- </div>
- </CardFooter>
+ <FormField_Shadcn_
+ control={githubSettingsForm.control}
+ name="branchLimit"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Branch limit"
+ description="Maximum number of preview branches"
+ >
+ <FormControl_Shadcn_>
+ <Input_Shadcn_
+ {...field}
+ type="number"
+ autoComplete="off"
+ value={!hasAccessToBranching ? 0 : field.value}
+ disabled={
+ !hasAccessToBranching ||
+ !newBranchPerPr ||
+ !canUpdateGitHubConnection
+ }
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+
+ <FormField_Shadcn_
+ control={githubSettingsForm.control}
+ name="supabaseChangesOnly"
+ render={({ field }) => (
+ <FormItemLayout
+ layout="flex-row-reverse"
+ label="Supabase changes only"
+ description="Only create branches when Supabase files change"
+ >
+ <FormControl_Shadcn_>
+ <Switch
+ checked={!hasAccessToBranching ? false : field.value}
+ onCheckedChange={(val) => field.onChange(val)}
+ disabled={
+ !hasAccessToBranching ||
+ !newBranchPerPr ||
+ !canUpdateGitHubConnection
+ }
+ />
+ </FormControl_Shadcn_>
+ </FormItemLayout>
+ )}
+ />
+ </div>
+ </div>
+ </CardContent>
+ <CardFooter className="flex justify-between items-center">
+ <div>
+ {connection && (
+ <Button
+ type="outline"
+ onClick={handleRemoveIntegration}
+ disabled={isDeletingConnection}
+ loading={isDeletingConnection}
+ >
+ Disable integration
+ </Button>
+ )}
+ </div>
+ <div className="flex space-x-2">
+ {githubSettingsForm.formState.isDirty && (
+ <Button
+ type="default"
+ onClick={() => githubSettingsForm.reset()}
+ disabled={!canUpdateGitHubConnection}
+ >
+ Cancel
+ </Button>
+ )}
+ <Button
+ type="default"
+ htmlType="submit"
+ disabled={
+ !hasAccessToGitHubIntegration ||
+ (!connection && !canCreateGitHubConnection) ||
+ (connection && !canUpdateGitHubConnection) ||
+ isCheckingBranch ||
+ isLoading ||
+ (!connection && !githubSettingsForm.getValues().repositoryId) ||
+ (connection && !githubSettingsForm.formState.isDirty)
+ }
+ loading={isCheckingBranch || isLoading}
+ >
+ {connection ? 'Save changes' : 'Enable integration'}
+ </Button>
+ </div>
+ </CardFooter>
+ </motion.div>
+ )}
+ </AnimatePresence>
</Card>
</form>
</Form_Shadcn_>
@@ -801,5 +830,3 @@ const GitHubIntegrationConnectionForm = ({
</>
)
}
-
-export default GitHubIntegrationConnectionForm
diff --git a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx
index 9ce834daa0b..f13f091d7c0 100644
--- a/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx
+++ b/apps/studio/components/interfaces/Settings/Integrations/GithubIntegration/GithubSection.tsx
@@ -1,7 +1,4 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
-import { useMemo } from 'react'
-
-import { useGitHubAuthorizationQuery } from '@/data/integrations/github-authorization-query'
import { useParams } from 'common'
import {
ScaffoldContainer,
@@ -10,13 +7,14 @@ import {
ScaffoldSectionDetail,
} from 'components/layouts/Scaffold'
import NoPermission from 'components/ui/NoPermission'
-import { UpgradeToPro } from 'components/ui/UpgradeToPro'
import { useGitHubConnectionsQuery } from 'data/integrations/github-connections-query'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import { BASE_PATH, IS_PLATFORM } from 'lib/constants'
+import { BASE_PATH } from 'lib/constants'
+import { useMemo } from 'react'
import { GenericSkeletonLoader } from 'ui-patterns'
-import GitHubIntegrationConnectionForm from './GitHubIntegrationConnectionForm'
+
+import { GitHubIntegrationConnectionForm } from './GitHubIntegrationConnectionForm'
const IntegrationImageHandler = ({ title }: { title: 'vercel' | 'github' }) => {
return (
@@ -35,11 +33,6 @@ export const GitHubSection = () => {
const { can: canReadGitHubConnection, isLoading: isLoadingPermissions } =
useAsyncCheckPermissions(PermissionAction.READ, 'integrations.github_connections')
- const isProPlanAndUp = organization?.plan?.id !== 'free'
- const promptProPlanUpgrade = IS_PLATFORM && !isProPlanAndUp
-
- const { data: gitHubAuthorization } = useGitHubAuthorizationQuery()
-
const { data: connections } = useGitHubConnectionsQuery(
{ organizationId: organization?.id },
{ enabled: !!projectRef && !!organization?.id }
@@ -66,35 +59,13 @@ export const GitHubSection = () => {
<NoPermission resourceText="view this organization's GitHub connections" />
) : (
<div className="space-y-6">
- <div>
- <h5 className="text-foreground mb-2">How does the GitHub integration work?</h5>
- <p className="text-foreground-light text-sm mb-6">
- Connecting to GitHub allows you to sync preview branches with a chosen GitHub
- branch, keep your production branch in sync, and automatically create preview
- branches for every pull request.
- </p>
-
- {promptProPlanUpgrade && (
- <div className="mb-6">
- <UpgradeToPro
- layout="vertical"
- source="github-integration"
- featureProposition="use GitHub integrations"
- primaryText={`Upgrade to ${!!existingConnection ? 'manage' : 'unlock'} GitHub integration`}
- secondaryText="Connect your GitHub repository to automatically sync preview branches and deploy changes."
- />
- </div>
- )}
-
- {/* [Joshen] Show connection form if GH has already been authorized OR no GH authorization but on a paid plan */}
- {/* So this shouldn't render if there's no GH authorization and on a free plan */}
- {(!!gitHubAuthorization || !promptProPlanUpgrade) && (
- <GitHubIntegrationConnectionForm
- disabled={promptProPlanUpgrade}
- connection={existingConnection}
- />
- )}
- </div>
+ <h5 className="text-foreground">How does the GitHub integration work?</h5>
+ <p className="text-foreground-light text-sm !mt-2">
+ Connecting to GitHub allows you to sync preview branches with a chosen GitHub
+ branch, keep your production branch in sync, and automatically create preview
+ branches for every pull request.
+ </p>
+ <GitHubIntegrationConnectionForm connection={existingConnection} />
</div>
)}
</ScaffoldSectionContent>
diff --git a/apps/studio/components/ui/UpgradeToPro.tsx b/apps/studio/components/ui/UpgradeToPro.tsx
index e7059d417d9..c7e8b5ebf28 100644
--- a/apps/studio/components/ui/UpgradeToPro.tsx
+++ b/apps/studio/components/ui/UpgradeToPro.tsx
@@ -1,7 +1,8 @@
import { ReactNode } from 'react'
-
import { cn } from 'ui'
import { Admonition } from 'ui-patterns'
+
+import { DocsButton } from './DocsButton'
import { UpgradePlanButton } from './UpgradePlanButton'
interface UpgradeToProProps {
@@ -21,6 +22,7 @@ interface UpgradeToProProps {
layout?: 'vertical' | 'horizontal'
variant?: 'default' | 'primary'
className?: string
+ docsUrl?: string
}
export const UpgradeToPro = ({
@@ -37,6 +39,7 @@ export const UpgradeToPro = ({
layout = 'horizontal',
variant = 'primary',
className,
+ docsUrl,
}: UpgradeToProProps) => {
return (
<Admonition
@@ -47,16 +50,19 @@ export const UpgradeToPro = ({
description={secondaryText}
className={cn(fullWidth && 'border-0 rounded-none border-b', className)}
actions={
- <UpgradePlanButton
- plan={planToUpgrade}
- addon={addon}
- source={source}
- featureProposition={featureProposition}
- disabled={disabled}
- variant={variant}
- >
- {buttonText}
- </UpgradePlanButton>
+ <>
+ <UpgradePlanButton
+ plan={planToUpgrade}
+ addon={addon}
+ source={source}
+ featureProposition={featureProposition}
+ disabled={disabled}
+ variant={variant}
+ >
+ {buttonText}
+ </UpgradePlanButton>
+ {!!docsUrl && <DocsButton href={docsUrl} />}
+ </>
}
/>
)