Skip to content

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

Merge branch 'master' into feat/github-integration

Alaister Youngaadb64cdde9b
diff --cc studio/components/interfaces/Integrations/ProjectLinker.tsx
index 88295e172d9,41cf88e40ed..1df94aed64d
--- a/studio/components/interfaces/Integrations/ProjectLinker.tsx
+++ b/studio/components/interfaces/Integrations/ProjectLinker.tsx
@@@ -12,21 -18,14 +12,22 @@@ export interface Project
ref: string
}
+export interface ForeignProject {
+ id: string
+ name: string
+}
+
export interface ProjectLinkerProps {
organizationIntegrationId: string | undefined
- foreignProjects: VercelProjectsResponse[]
+ foreignProjects: ForeignProject[]
supabaseProjects: Project[]
- onCreateConnections?: () => void
+ onCreateConnections: (variables: IntegrationConnectionsCreateVariables) => void
installedConnections: IntegrationProjectConnection[] | undefined
- setLoading?: (x: boolean) => void
- showSkip?: boolean
+ isLoading?: boolean
+ integrationIcon: ReactNode
+ getForeignProjectIcon?: (project: ForeignProject) => ReactNode
+ choosePrompt?: string
++ onSkip?: () => void
}
const UNDEFINED_SELECT_VALUE = 'undefined'
@@@ -37,10 -36,8 +38,11 @@@ const ProjectLinker = (
supabaseProjects,
onCreateConnections: _onCreateConnections,
installedConnections = [],
- setLoading,
- showSkip = false,
+ isLoading,
+ integrationIcon,
+ getForeignProjectIcon,
+ choosePrompt = 'Choose a project',
++ onSkip,
}: ProjectLinkerProps) => {
const selectedOrganization = useSelectedOrganization()
@@@ -165,7 -209,18 +167,18 @@@
</Panel>
</div>
</div>
- <div className="flex w-full justify-end">
+ <div className="flex w-full justify-end gap-2">
- {showSkip && (
++ {onSkip !== undefined && (
+ <Button
+ size="medium"
+ type="default"
+ onClick={() => {
- _onCreateConnections?.()
++ onSkip()
+ }}
+ >
+ Skip
+ </Button>
+ )}
<Button
size="medium"
className="self-end"
diff --cc studio/data/api.d.ts
index 88909a8dd2a,b76fee25169..ebb7e809177
--- a/studio/data/api.d.ts
+++ b/studio/data/api.d.ts
@@@ -704,29 -712,6 +712,30 @@@ export interface paths
/** Deletes vercel project connection */
delete: operations["VercelConnectionsController_deleteVercelConnection"];
};
+ "/platform/integrations/github": {
- /**
- * Create github integration
- * @description Exchanges a github code for an access token and saves the access token to the new integration record
- */
++ /** Create github integration */
+ post: operations["GitHubIntegrationController_createGitHubIntegration"];
+ };
- "/platform/integrations/github/repos/{organization_integration_id}": {
- /** Gets github repos for the given organization */
- get: operations["GitHubRepoController_getRepos"];
- };
+ "/platform/integrations/github/connections/{organization_integration_id}": {
+ /** Gets installed github project connections for the given organization integration */
+ get: operations["GitHubConnectionsController_getGitHubConnections"];
+ };
+ "/platform/integrations/github/connections": {
+ /** Connects a GitHub project to a supabase project */
+ post: operations["GitHubConnectionsController_createGitHubConnection"];
+ };
+ "/platform/integrations/github/connections/{connection_id}": {
+ /** Deletes github project connection */
+ delete: operations["GitHubConnectionsController_deleteGitHubConnection"];
+ };
++ "/platform/integrations/github/repos/{organization_integration_id}": {
++ /** Gets github repos for the given organization */
++ get: operations["GitHubRepoController_getRepos"];
++ };
++ "/platform/integrations/github/branches/{organization_integration_id}/{repo_owner}/{repo_name}": {
++ /** Gets github branches for a given repo */
++ get: operations["GitHubBranchController_getBranches"];
++ };
"/system/auth/{ref}/templates/{template}": {
/** Gets GoTrue template */
get: operations["AuthTemplateController_getTemplate"];
@@@ -803,6 -792,6 +816,10 @@@
/** Processes Vercel event */
post: operations["VercelWebhooksController_processEvent"];
};
++ "/system/integrations/github/webhooks": {
++ /** Processes GitHub event */
++ post: operations["GitHubWebhooksController_processEvent"];
++ };
"/system/stripe/webhooks-v2": {
/** Processes Stripe event */
post: operations["StripeWebhooksController_processEvent"];
@@@ -3743,27 -3786,12 +3814,40 @@@ export interface components
organization_integration_id: string;
connection: components["schemas"]["IntegrationConnection"];
};
+ CreateVercelConnectionResponse: {
+ id: string;
+ };
+ DeleteVercelConnectionResponse: {
+ id: string;
+ };
+ CreateGitHubIntegrationBody: {
+ installation_id: number;
+ organization_slug: string;
+ metadata: Record<string, never>;
+ };
+ CreateGitHubIntegrationResponse: {
+ id: string;
+ };
+ GetGitHubConnections: {
+ id: string;
+ inserted_at: string;
+ updated_at: string;
+ organization_integration_id: string;
+ supabase_project_ref: string;
+ foreign_project_id: string;
+ metadata: Record<string, never>;
+ };
+ CreateGitHubConnectionsBody: {
+ organization_integration_id: string;
+ connection: components["schemas"]["IntegrationConnection"];
+ };
++ GetGithubRepo: {
++ id: number;
++ full_name: string;
++ };
++ GetGithubBranch: {
++ name: string;
++ };
FunctionResponse: {
id: string;
slug: string;
@@@ -8173,82 -8270,6 +8326,102 @@@ export interface operations
500: never;
};
};
- /**
- * Create github integration
- * @description Exchanges a github code for an access token and saves the access token to the new integration record
- */
++ /** Create github integration */
+ GitHubIntegrationController_createGitHubIntegration: {
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["CreateGitHubIntegrationBody"];
+ };
+ };
+ responses: {
+ 201: {
+ content: {
+ "application/json": components["schemas"]["CreateGitHubIntegrationResponse"];
+ };
+ };
+ /** @description Failed to create github integration */
+ 500: never;
+ };
+ };
- /** Gets github repos for the given organization */
- GitHubRepoController_getRepos: {
- parameters: {
- path: {
- organization_integration_id: string;
- };
- };
- responses: {
- 200: never;
- /** @description Failed to get github repos for the given organization */
- 500: never;
- };
- };
+ /** Gets installed github project connections for the given organization integration */
+ GitHubConnectionsController_getGitHubConnections: {
+ parameters: {
+ path: {
+ organization_integration_id: string;
+ };
+ };
+ responses: {
+ 200: {
+ content: {
+ "application/json": (components["schemas"]["GetGitHubConnections"])[];
+ };
+ };
+ /** @description Failed to get installed github connections for the given organization integration */
+ 500: never;
+ };
+ };
+ /** Connects a GitHub project to a supabase project */
+ GitHubConnectionsController_createGitHubConnection: {
+ requestBody: {
+ content: {
+ "application/json": components["schemas"]["CreateGitHubConnectionsBody"];
+ };
+ };
+ responses: {
+ 201: never;
+ /** @description Failed to create project connections */
+ 500: never;
+ };
+ };
+ /** Deletes github project connection */
+ GitHubConnectionsController_deleteGitHubConnection: {
+ parameters: {
+ path: {
+ connection_id: string;
+ };
+ };
+ responses: {
+ 200: never;
+ /** @description Failed to delete github integration project connection */
+ 500: never;
+ };
+ };
++ /** Gets github repos for the given organization */
++ GitHubRepoController_getRepos: {
++ parameters: {
++ path: {
++ organization_integration_id: string;
++ };
++ };
++ responses: {
++ 200: {
++ content: {
++ "application/json": (components["schemas"]["GetGithubRepo"])[];
++ };
++ };
++ /** @description Failed to get github repos for the given organization */
++ 500: never;
++ };
++ };
++ /** Gets github branches for a given repo */
++ GitHubBranchController_getBranches: {
++ parameters: {
++ path: {
++ organization_integration_id: string;
++ repo_owner: string;
++ repo_name: string;
++ };
++ };
++ responses: {
++ 200: {
++ content: {
++ "application/json": (components["schemas"]["GetGithubBranch"])[];
++ };
++ };
++ /** @description Failed to get github branches for a given repo */
++ 500: never;
++ };
++ };
/** Gets GoTrue template */
AuthTemplateController_getTemplate: {
parameters: {
@@@ -8597,6 -8631,6 +8783,25 @@@
500: never;
};
};
++ /** Processes GitHub event */
++ GitHubWebhooksController_processEvent: {
++ parameters: {
++ header: {
++ "x-github-delivery": string;
++ "x-hub-signature-256": string;
++ };
++ };
++ requestBody: {
++ content: {
++ "application/json": components["schemas"]["Buffer"];
++ };
++ };
++ responses: {
++ 201: never;
++ /** @description Failed to process GitHub event */
++ 500: never;
++ };
++ };
/** Processes Stripe event */
StripeWebhooksController_processEvent: {
parameters: {
diff --cc studio/data/integrations/integrations-vercel-connections-create-mutation.ts
index edf8799d9e5,b72f4bb064e..ad241649881
--- a/studio/data/integrations/integrations-vercel-connections-create-mutation.ts
+++ b/studio/data/integrations/integrations-vercel-connections-create-mutation.ts
@@@ -1,29 -1,42 +1,35 @@@
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
- import { post } from 'lib/common/fetch'
- import { API_URL } from 'lib/constants'
+
+ import { post } from 'data/fetchers'
import { integrationKeys } from './keys'
+import { IntegrationConnectionsCreateVariables } from './types'
-export type IntegrationConnectionsCreateVariables = {
- organizationIntegrationId: string
- connection: {
- foreign_project_id: string
- supabase_project_ref: string
- metadata: any
- }
- orgSlug: string | undefined
-}
-
-export async function createIntegrationConnections({
+export async function createIntegrationVercelConnections({
organizationIntegrationId,
connection,
}: IntegrationConnectionsCreateVariables) {
- const response = await post(`${API_URL}/integrations/vercel/connections`, {
- organization_integration_id: organizationIntegrationId,
- connection,
+ const { data, error } = await post('/platform/integrations/vercel/connections', {
+ body: {
+ organization_integration_id: organizationIntegrationId,
+ connection: {
+ foreign_project_id: connection.foreign_project_id,
+ supabase_project_ref: connection.supabase_project_ref,
+ metadata: connection.metadata,
+ },
+ },
})
- if (response.error) {
- throw response.error
+ if (error) {
+ throw error
}
- return response
+ return data
}
-type IntegrationConnectionsCreateData = Awaited<ReturnType<typeof createIntegrationConnections>>
+export type IntegrationVercelConnectionsCreateData = Awaited<
+ ReturnType<typeof createIntegrationVercelConnections>
+>
-export const useIntegrationConnectionsCreateMutation = ({
+export const useIntegrationVercelConnectionsCreateMutation = ({
onSuccess,
...options
}: Omit<
diff --cc studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
index abf5107a1be,80bd6c8d3ef..af506539b25
--- a/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
+++ b/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
@@@ -8,8 -8,9 +8,9 @@@ import { VercelIntegrationLayout } fro
import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
import PasswordStrengthBar from 'components/ui/PasswordStrengthBar'
import { useProjectApiQuery } from 'data/config/project-api-query'
- import { useIntegrationVercelConnectionsCreateMutation } from 'data/integrations/integrations-vercel-connections-create-mutation'
-import { useIntegrationConnectionsCreateMutation } from 'data/integrations/integration-connections-create-mutation'
import { useIntegrationsQuery } from 'data/integrations/integrations-query'
+ import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation'
++import { useIntegrationVercelConnectionsCreateMutation } from 'data/integrations/integrations-vercel-connections-create-mutation'
import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
import { Integration } from 'data/integrations/integrations.types'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
@@@ -93,7 -94,8 +94,8 @@@ const CreateProject = (
} = useParams()
const { mutateAsync: createConnections, isLoading: isLoadingCreateConnections } =
- useIntegrationConnectionsCreateMutation()
+ useIntegrationVercelConnectionsCreateMutation()
+ const { mutateAsync: syncEnvs } = useIntegrationsVercelConnectionSyncEnvsMutation()
const { data: organizationData, isLoading: isLoadingOrganizationsQuery } = useOrganizationsQuery()
diff --cc studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
index 0cb0cacc947,bbb7dbd0b86..aeaa77c4995
--- a/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
+++ b/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
@@@ -12,18 -9,9 +12,20 @@@ import { useIntegrationVercelConnection
import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
import { useProjectsQuery } from 'data/projects/projects-query'
+import { BASE_PATH } from 'lib/constants'
import { EMPTY_ARR } from 'lib/void'
+
import { NextPageWithLayout, Organization } from 'types'
import { IconBook, IconLifeBuoy, LoadingLine } from 'ui'
+import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integrations-Vercel.constants'
++import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation'
++import { toast } from 'react-hot-toast'
+
+const VERCEL_ICON = (
+ <svg xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0 0 512 512" className="w-6">
+ <path fill-rule="evenodd" d="M256,48,496,464H16Z" />
+ </svg>
+)
const VercelIntegration: NextPageWithLayout = () => {
const { slug, configurationId, next, organizationSlug } = useParams()
@@@ -71,54 -56,6 +73,61 @@@
)
const vercelProjects = useMemo(() => vercelProjectsData ?? EMPTY_ARR, [vercelProjectsData])
+ const vercelProjectsById = useMemo(() => keyBy(vercelProjects, 'id'), [vercelProjects])
+
+ const getForeignProjectIcon = useCallback(
+ (_project: ForeignProject) => {
+ const project = vercelProjectsById[_project.id]
+
+ return !project?.framework ? (
+ vercelIcon
+ ) : (
+ <img
+ src={`${BASE_PATH}/img/icons/frameworks/${project.framework}.svg`}
+ width={21}
+ height={21}
+ alt={`icon`}
+ />
+ )
+ },
+ [vercelProjectsById]
+ )
+
++ const { mutateAsync: syncEnvs } = useIntegrationsVercelConnectionSyncEnvsMutation()
+ const { mutate: createConnections, isLoading: isCreatingConnection } =
+ useIntegrationVercelConnectionsCreateMutation({
- onSuccess() {
++ async onSuccess({ id }) {
++ try {
++ await syncEnvs({ connectionId: id })
++ } catch (error: any) {
++ toast.error('Failed to sync environment variables: ', error.message)
++ }
++
+ if (next) {
+ window.location.href = next
+ }
+ },
+ })
+
+ const onCreateConnections = useCallback(
+ (vars) => {
+ createConnections({
+ ...vars,
+ connection: {
+ ...vars.connection,
+ metadata: {
+ ...vars.connection.metadata,
+ supabaseConfig: {
+ projectEnvVars: {
+ write: true,
+ },
+ },
+ },
+ },
+ })
+ },
+ [createConnections]
+ )
return (
<>
@@@ -141,24 -78,14 +150,29 @@@ This Supabase integration manages your
organizationIntegrationId={integration?.id}
foreignProjects={vercelProjects}
supabaseProjects={supabaseProjects}
- onCreateConnections={() => {
+ onCreateConnections={onCreateConnections}
+ installedConnections={integration?.connections}
+ isLoading={isCreatingConnection}
+ integrationIcon={VERCEL_ICON}
+ getForeignProjectIcon={getForeignProjectIcon}
+ choosePrompt="Choose Vercel Project"
++ onSkip={() => {
+ if (next) {
+ window.location.href = next
+ }
+ }}
- installedConnections={integration?.connections}
- setLoading={setLoading}
- showSkip={true}
+ />
+ <Markdown
+ content={`
+The following environment variables will be added:
+
+${ENV_VAR_RAW_KEYS.map((x) => {
+ return `
+ \n
+ - \`${x}\`
+`
+})}
+`}
/>
</ScaffoldContainer>
</>