Skip to content

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

working github integration

Alaister Youngdb34ee6cf900
diff --git a/studio/components/interfaces/Integrations/ProjectLinker.tsx b/studio/components/interfaces/Integrations/ProjectLinker.tsx
index 0be4ac9d5d4..88295e172d9 100644
--- a/studio/components/interfaces/Integrations/ProjectLinker.tsx
+++ b/studio/components/interfaces/Integrations/ProjectLinker.tsx
@@ -1,28 +1,32 @@
-import { useState } from 'react'
+import { ReactNode, useState } from 'react'
-import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integrations-Vercel.constants'
-import { Markdown } from 'components/interfaces/Markdown'
-import { vercelIcon } from 'components/to-be-cleaned/ListIcons'
-import { useIntegrationConnectionsCreateMutation } from 'data/integrations/integration-connections-create-mutation'
-import { VercelProjectsResponse } from 'data/integrations/integrations-vercel-projects-query'
import { IntegrationProjectConnection } from 'data/integrations/integrations.types'
+import { IntegrationConnectionsCreateVariables } from 'data/integrations/types'
import { useSelectedOrganization } from 'hooks'
import { BASE_PATH } from 'lib/constants'
import { Button, Listbox, cn } from 'ui'
-interface Project {
+export interface Project {
id: string
name: string
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
+ isLoading?: boolean
+ integrationIcon: ReactNode
+ getForeignProjectIcon?: (project: ForeignProject) => ReactNode
+ choosePrompt?: string
}
const UNDEFINED_SELECT_VALUE = 'undefined'
@@ -33,45 +37,31 @@ const ProjectLinker = ({
supabaseProjects,
onCreateConnections: _onCreateConnections,
installedConnections = [],
- setLoading,
+ isLoading,
+ integrationIcon,
+ getForeignProjectIcon,
+ choosePrompt = 'Choose a project',
}: ProjectLinkerProps) => {
const selectedOrganization = useSelectedOrganization()
const [supabaseProjectRef, setSupabaseProjectRef] = useState(UNDEFINED_SELECT_VALUE)
- const [vercelProjectId, setVercelProjectId] = useState(UNDEFINED_SELECT_VALUE)
-
- const { mutate: createConnections, isLoading } = useIntegrationConnectionsCreateMutation({
- onSuccess() {
- _onCreateConnections?.()
- },
-
- onSettled() {
- if (setLoading) setLoading(false)
- },
- })
+ const [foreignProjectId, setForeignProjectId] = useState(UNDEFINED_SELECT_VALUE)
function onCreateConnections() {
- const projectDetails = foreignProjects.filter((x) => x.id === vercelProjectId)[0]
+ const projectDetails = foreignProjects.filter((x) => x.id === foreignProjectId)[0]
if (!organizationIntegrationId) {
console.error('No integration ID set')
return
}
- if (setLoading) setLoading(true)
-
- createConnections({
+ _onCreateConnections({
organizationIntegrationId,
connection: {
- foreign_project_id: vercelProjectId,
+ foreign_project_id: foreignProjectId,
supabase_project_ref: supabaseProjectRef,
metadata: {
...projectDetails,
- supabaseConfig: {
- projectEnvVars: {
- write: true,
- },
- },
},
},
orgSlug: selectedOrganization?.slug,
@@ -95,12 +85,10 @@ const ProjectLinker = ({
// create a flat array of foreign project ids. ie, ["prj_MlkO6AiLG5ofS9ojKrkS3PhhlY3f", ..]
const flatInstalledConnectionsIds = new Set(installedConnections.map((x) => x.foreign_project_id))
- // check that vercel project is not already installed
- const filteredForeignProjects: VercelProjectsResponse[] = foreignProjects.filter(
- (foreignProject) => {
- return !flatInstalledConnectionsIds.has(foreignProject.id)
- }
- )
+ // check that foreign project is not already installed
+ const filteredForeignProjects = foreignProjects.filter((foreignProject) => {
+ return !flatInstalledConnectionsIds.has(foreignProject.id)
+ })
return (
<div className="flex flex-col gap-4">
@@ -149,23 +137,15 @@ const ProjectLinker = ({
<div className="border border-scale-1000 h-px w-16 border-dashed self-end mb-5"></div>
<Panel>
<div className="bg-black shadow rounded p-1 w-12 h-12 flex justify-center items-center">
- {/* <img src="/img/icons/vercel.svg" style={{ height: 21 }} alt="integration 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>
+ {integrationIcon}
</div>
<Listbox
className="w-full"
- value={vercelProjectId ?? UNDEFINED_SELECT_VALUE}
- onChange={(e) => setVercelProjectId(e)}
+ value={foreignProjectId ?? UNDEFINED_SELECT_VALUE}
+ onChange={(e) => setForeignProjectId(e)}
>
- <Listbox.Option value={UNDEFINED_SELECT_VALUE} label="Choose a project" disabled>
- Choose Vercel project
+ <Listbox.Option value={UNDEFINED_SELECT_VALUE} label={choosePrompt} disabled>
+ {choosePrompt}
</Listbox.Option>
{filteredForeignProjects.map((project) => {
return (
@@ -174,20 +154,7 @@ const ProjectLinker = ({
value={project.id}
label={project.name}
addOnBefore={() => {
- return (
- <>
- {!project?.framework ? (
- vercelIcon
- ) : (
- <img
- src={`${BASE_PATH}/img/icons/frameworks/${project.framework}.svg`}
- width={21}
- height={21}
- alt={`icon`}
- />
- )}
- </>
- )
+ return getForeignProjectIcon?.(project) ?? null
}}
>
{project.name}
@@ -209,18 +176,6 @@ const ProjectLinker = ({
Connect project
</Button>
</div>
- <Markdown
- content={`
-The following environment variables will be added:
-
-${ENV_VAR_RAW_KEYS.map((x, idx) => {
- return `
- \n
- - \`${x}\`
-`
-})}
-`}
- />
</div>
)
}
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
index b19821e45d0..d3091a75519 100644
--- a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
+++ b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
@@ -77,8 +77,6 @@ You can change the scope of the access for Supabase by configuring [here](${getV
Connect any of your GitHub repositories to a project.
`}
description={`
-GitHub connections are coming soon.
-
### How will GitHub connections work?
You will be able to connect a GitHub repository to a Supabase project.
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
index 6beed7de861..e3ac21e5850 100644
--- a/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
+++ b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
@@ -1,15 +1,26 @@
-import { useMemo } from 'react'
+import { keyBy } from 'lodash'
+import { useCallback, useMemo } from 'react'
-import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
+import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integrations-Vercel.constants'
+import ProjectLinker, { ForeignProject } from 'components/interfaces/Integrations/ProjectLinker'
import { Markdown } from 'components/interfaces/Markdown'
+import { vercelIcon } from 'components/to-be-cleaned/ListIcons'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
+import { useIntegrationVercelConnectionsCreateMutation } from 'data/integrations/integrations-vercel-connections-create-mutation'
import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
import { useProjectsQuery } from 'data/projects/projects-query'
import { useSelectedOrganization } from 'hooks'
+import { BASE_PATH } from 'lib/constants'
import { EMPTY_ARR } from 'lib/void'
import { useGithubConnectionConfigPanelSnapshot } from 'state/github-connection-config-panel'
import { SidePanel } from 'ui'
+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 SidePanelVercelProjectLinker = () => {
const selectedOrganization = useSelectedOrganization()
@@ -58,6 +69,52 @@ const SidePanelVercelProjectLinker = () => {
)
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 { mutate: createConnections, isLoading: isCreatingConnection } =
+ useIntegrationVercelConnectionsCreateMutation({
+ onSuccess() {
+ snapshot.setOpen(false)
+ },
+ })
+
+ const onCreateConnections = useCallback(
+ (vars) => {
+ createConnections({
+ ...vars,
+ connection: {
+ ...vars.connection,
+ metadata: {
+ ...vars.connection.metadata,
+ supabaseConfig: {
+ projectEnvVars: {
+ write: true,
+ },
+ },
+ },
+ },
+ })
+ },
+ [createConnections]
+ )
return (
<SidePanel
@@ -82,10 +139,24 @@ Check the details below before proceeding
organizationIntegrationId={selectedIntegration?.id}
foreignProjects={vercelProjects}
supabaseProjects={supabaseProjects}
- onCreateConnections={() => {
- snapshot.setOpen(false)
- }}
+ onCreateConnections={onCreateConnections}
installedConnections={selectedIntegration?.connections}
+ isLoading={isCreatingConnection}
+ integrationIcon={VERCEL_ICON}
+ getForeignProjectIcon={getForeignProjectIcon}
+ choosePrompt="Choose Vercel Project"
+ />
+ <Markdown
+ content={`
+The following environment variables will be added:
+
+${ENV_VAR_RAW_KEYS.map((x) => {
+ return `
+ \n
+ - \`${x}\`
+`
+})}
+`}
/>
</SidePanel.Content>
<SidePanel.Content>
diff --git a/studio/data/integrations/github-integration-create-mutation.ts b/studio/data/integrations/github-integration-create-mutation.ts
index 73ce49b48b4..8ae13f84b94 100644
--- a/studio/data/integrations/github-integration-create-mutation.ts
+++ b/studio/data/integrations/github-integration-create-mutation.ts
@@ -4,20 +4,17 @@ import { API_URL } from 'lib/constants'
import { integrationKeys } from './keys'
export type GitHubIntegrationCreateVariables = {
- code: string
installationId: string
orgSlug: string
metadata: { [key: string]: string }
}
export async function createGitHubIntegration({
- code,
installationId,
orgSlug,
metadata,
}: GitHubIntegrationCreateVariables) {
const response = await post(`${API_URL}/integrations/github`, {
- code,
installation_id: installationId,
organization_slug: orgSlug,
metadata,
diff --git a/studio/data/integrations/integrations-github-connections-create-mutation.ts b/studio/data/integrations/integrations-github-connections-create-mutation.ts
new file mode 100644
index 00000000000..6a924b9e509
--- /dev/null
+++ b/studio/data/integrations/integrations-github-connections-create-mutation.ts
@@ -0,0 +1,58 @@
+import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
+import { post } from 'lib/common/fetch'
+import { API_URL } from 'lib/constants'
+import { integrationKeys } from './keys'
+import { IntegrationConnectionsCreateVariables } from './types'
+
+export async function createIntegrationGitHubConnections({
+ organizationIntegrationId,
+ connection,
+}: IntegrationConnectionsCreateVariables) {
+ const response = await post(`${API_URL}/integrations/github/connections`, {
+ organization_integration_id: organizationIntegrationId,
+ connection,
+ })
+ if (response.error) {
+ throw response.error
+ }
+
+ return response
+}
+
+export type IntegrationGitHubConnectionsCreateData = Awaited<
+ ReturnType<typeof createIntegrationGitHubConnections>
+>
+
+export const useIntegrationGitHubConnectionsCreateMutation = ({
+ onSuccess,
+ ...options
+}: Omit<
+ UseMutationOptions<
+ IntegrationGitHubConnectionsCreateData,
+ unknown,
+ IntegrationConnectionsCreateVariables
+ >,
+ 'mutationFn'
+> = {}) => {
+ const queryClient = useQueryClient()
+ return useMutation<
+ IntegrationGitHubConnectionsCreateData,
+ unknown,
+ IntegrationConnectionsCreateVariables
+ >((vars) => createIntegrationGitHubConnections(vars), {
+ async onSuccess(data, variables, context) {
+ await Promise.all([
+ queryClient.invalidateQueries(integrationKeys.integrationsList()),
+ queryClient.invalidateQueries(integrationKeys.integrationsListWithOrg(variables.orgSlug)),
+ queryClient.invalidateQueries(
+ integrationKeys.githubRepoList(variables.organizationIntegrationId)
+ ),
+ queryClient.invalidateQueries(
+ integrationKeys.githubConnectionsList(variables.organizationIntegrationId)
+ ),
+ ])
+ await onSuccess?.(data, variables, context)
+ },
+ ...options,
+ })
+}
diff --git a/studio/data/integrations/integrations-github-repos-query.ts b/studio/data/integrations/integrations-github-repos-query.ts
index 4b1141df100..5bbc2be894c 100644
--- a/studio/data/integrations/integrations-github-repos-query.ts
+++ b/studio/data/integrations/integrations-github-repos-query.ts
@@ -1,137 +1,47 @@
-import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
import { integrationKeys } from './keys'
-// repos fetch
-export type IntegrationsVariables = {
- orgSlug?: string
+export type GitHubReposVariables = {
+ integrationId: string | undefined
}
-export type IntegrationProjectConnection = {
- id: string
- createdAt: string
- from: {
- name: string
- }
- to: {
- name: string
- }
+export type GitHubReposResponse = {
+ id: number
+ full_name: string
}
-export type Integration = {
- id: string
- type: 'VERCEL' | 'NETLIFY' | 'GITHUB'
- createdBy: string
- createdAt: string
- connections: IntegrationProjectConnection[]
- metadata?: {
- vercelTeam?: string
- gitHubConnectionOwner?: string
+export async function getGitHubRepos(
+ { integrationId }: GitHubReposVariables,
+ signal?: AbortSignal
+) {
+ if (!integrationId) {
+ throw new Error('integrationId is required')
}
-}
-export type IntegrationsResponse = Integration[]
-
-export async function getIntegrations({ orgSlug }: IntegrationsVariables, signal?: AbortSignal) {
- if (!orgSlug) {
- throw new Error('orgSlug is required')
+ const response = await get(`${API_URL}/integrations/github/repos/${integrationId}`, {
+ signal,
+ })
+ if (response.error) {
+ throw response.error
}
- const response: IntegrationsResponse = [
- {
- id: '1',
- type: 'VERCEL',
- createdBy: '[email protected]',
- createdAt: '2023-06-05T06:56:25.565Z',
- metadata: {
- vercelTeam: 'alaister-team',
- },
- connections: [
- {
- id: '1.0',
- createdAt: '2023-06-05T01:56:25.565Z',
- to: {
- name: 'www prod',
- },
- from: {
- name: 'alaister project prod',
- },
- },
- {
- id: '1.1',
- createdAt: '2023-06-14T06:56:25.565Z',
- to: {
- name: 'www staging',
- },
- from: {
- name: 'alaister project staging',
- },
- },
- {
- id: '1.1',
- createdAt: '2023-06-02T21:56:25.565Z',
- to: {
- name: 'bees knees',
- },
- from: {
- name: 'jonny bee project',
- },
- },
- ],
- },
- {
- id: '2',
- type: 'VERCEL',
- createdBy: '[email protected]',
- createdAt: '2023-06-05T06:56:25.565Z',
- metadata: {
- vercelTeam: 'alaister-team',
- },
- connections: [],
- },
- {
- id: '3',
- type: 'GITHUB',
- createdBy: 'Alaister',
- createdAt: '2023-06-05T06:56:25.565Z',
- metadata: {
- gitHubConnectionOwner: 'alaister',
- },
- connections: [
- {
- id: '1.2',
- createdAt: '2023-06-05T06:56:25.565Z',
- to: {
- name: 'supabase/supabase',
- },
- from: {
- name: 'alaister project',
- },
- },
- ],
- },
- ]
-
- // const response = await get(`${API_URL}/projects/${orgSlug}/integrations`, {
- // signal,
- // })
- // if (response.error) {
- // throw response.error
- // }
-
- return response as IntegrationsResponse
+ return response as GitHubReposResponse[]
}
-export type IntegrationsData = Awaited<ReturnType<typeof getIntegrations>>
-export type IntegrationsError = unknown
+export type GitHubReposData = Awaited<ReturnType<typeof getGitHubRepos>>
+export type GitHubReposError = unknown
-export const useIntegrationsGitHubReposQuery = <TData = IntegrationsData>(
- { orgSlug }: IntegrationsVariables,
- { enabled = true, ...options }: UseQueryOptions<IntegrationsData, IntegrationsError, TData> = {}
+export const useGitHubReposQuery = <TData = GitHubReposData>(
+ { integrationId }: GitHubReposVariables,
+ { enabled = true, ...options }: UseQueryOptions<GitHubReposData, GitHubReposError, TData> = {}
) =>
- useQuery<IntegrationsData, IntegrationsError, TData>(
- integrationKeys.integrationsList(), // TODO: make a unique key for github repos
- ({ signal }) => getIntegrations({ orgSlug }, signal),
- { enabled: enabled && typeof orgSlug !== 'undefined', ...options }
+ useQuery<GitHubReposData, GitHubReposError, TData>(
+ integrationKeys.githubRepoList(integrationId),
+ ({ signal }) => getGitHubRepos({ integrationId }, signal),
+ {
+ enabled: enabled && typeof integrationId !== 'undefined',
+ ...options,
+ }
)
diff --git a/studio/data/integrations/integrations-query.ts b/studio/data/integrations/integrations-query.ts
index a522135fa2a..4549f2d6bf0 100644
--- a/studio/data/integrations/integrations-query.ts
+++ b/studio/data/integrations/integrations-query.ts
@@ -1,12 +1,12 @@
-import { useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query'
+import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { get } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
+import { Integration } from './integrations.types'
import { integrationKeys } from './keys'
-import { IntegrationsVariables, Integration } from './integrations.types'
export type IntegrationsResponse = Integration[]
-export async function getIntegrations({}: {}, signal?: AbortSignal) {
+export async function getIntegrations(signal?: AbortSignal) {
const response = await get(`${API_URL}/integrations`, {
signal,
})
@@ -27,6 +27,6 @@ export const useIntegrationsQuery = <TData = IntegrationsData>({
}: UseQueryOptions<IntegrationsData, IntegrationsError, TData> = {}) =>
useQuery<IntegrationsData, IntegrationsError, TData>(
integrationKeys.integrationsList(),
- ({ signal }) => getIntegrations({}, signal),
+ ({ signal }) => getIntegrations(signal),
{ enabled: enabled, ...options }
)
diff --git a/studio/data/integrations/integration-connections-create-mutation.ts b/studio/data/integrations/integrations-vercel-connections-create-mutation.ts
similarity index 71%
rename from studio/data/integrations/integration-connections-create-mutation.ts
rename to studio/data/integrations/integrations-vercel-connections-create-mutation.ts
index 9431e94aafb..edf8799d9e5 100644
--- a/studio/data/integrations/integration-connections-create-mutation.ts
+++ b/studio/data/integrations/integrations-vercel-connections-create-mutation.ts
@@ -2,18 +2,9 @@ import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react
import { post } from 'lib/common/fetch'
import { API_URL } from 'lib/constants'
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) {
@@ -28,14 +19,16 @@ export async function createIntegrationConnections({
return response
}
-type IntegrationConnectionsCreateData = Awaited<ReturnType<typeof createIntegrationConnections>>
+export type IntegrationVercelConnectionsCreateData = Awaited<
+ ReturnType<typeof createIntegrationVercelConnections>
+>
-export const useIntegrationConnectionsCreateMutation = ({
+export const useIntegrationVercelConnectionsCreateMutation = ({
onSuccess,
...options
}: Omit<
UseMutationOptions<
- IntegrationConnectionsCreateData,
+ IntegrationVercelConnectionsCreateData,
unknown,
IntegrationConnectionsCreateVariables
>,
@@ -43,10 +36,10 @@ export const useIntegrationConnectionsCreateMutation = ({
> = {}) => {
const queryClient = useQueryClient()
return useMutation<
- IntegrationConnectionsCreateData,
+ IntegrationVercelConnectionsCreateData,
unknown,
IntegrationConnectionsCreateVariables
- >((vars) => createIntegrationConnections(vars), {
+ >((vars) => createIntegrationVercelConnections(vars), {
async onSuccess(data, variables, context) {
await Promise.all([
queryClient.invalidateQueries(integrationKeys.integrationsList()),
diff --git a/studio/data/integrations/keys.ts b/studio/data/integrations/keys.ts
index c099d9d7783..cf889d06b13 100644
--- a/studio/data/integrations/keys.ts
+++ b/studio/data/integrations/keys.ts
@@ -4,6 +4,10 @@ export const integrationKeys = {
integrationsList: () => ['organizations', 'integrations'] as const,
vercelProjectList: (organization_integration_id: string | undefined) =>
['organizations', organization_integration_id, 'vercel-projects'] as const,
+ githubRepoList: (organization_integration_id: string | undefined) =>
+ ['organizations', organization_integration_id, 'github-repos'] as const,
vercelConnectionsList: (organization_integration_id: string | undefined) =>
['organizations', organization_integration_id, 'vercel-connections'] as const,
+ githubConnectionsList: (organization_integration_id: string | undefined) =>
+ ['organizations', organization_integration_id, 'github-connections'] as const,
}
diff --git a/studio/data/integrations/types.ts b/studio/data/integrations/types.ts
new file mode 100644
index 00000000000..50ff9e34d05
--- /dev/null
+++ b/studio/data/integrations/types.ts
@@ -0,0 +1,9 @@
+export type IntegrationConnectionsCreateVariables = {
+ organizationIntegrationId: string
+ connection: {
+ foreign_project_id: string
+ supabase_project_ref: string
+ metadata: any
+ }
+ orgSlug: string | undefined
+}
diff --git a/studio/next.config.js b/studio/next.config.js
index d95d252877e..5a10643bf13 100644
--- a/studio/next.config.js
+++ b/studio/next.config.js
@@ -201,7 +201,12 @@ const nextConfig = {
]
},
images: {
- domains: ['github.com', 'api-frameworks.vercel.sh', 'vercel.com'],
+ domains: [
+ 'github.com',
+ 'avatars.githubusercontent.com',
+ 'api-frameworks.vercel.sh',
+ 'vercel.com',
+ ],
},
// Ref: https://nextjs.org/docs/advanced-features/output-file-tracing#caveats
experimental: {
diff --git a/studio/pages/integrations/github/[integrationId]/choose-project.tsx b/studio/pages/integrations/github/[integrationId]/choose-project.tsx
new file mode 100644
index 00000000000..dc1d7545f93
--- /dev/null
+++ b/studio/pages/integrations/github/[integrationId]/choose-project.tsx
@@ -0,0 +1,116 @@
+import { useParams } from 'common'
+import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
+import { Markdown } from 'components/interfaces/Markdown'
+import GitHubIntegrationWindowLayout from 'components/layouts/IntegrationsLayout/GitHubIntegrationWindowLayout'
+import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
+import { useIntegrationGitHubConnectionsCreateMutation } from 'data/integrations/integrations-github-connections-create-mutation'
+import { useGitHubReposQuery } from 'data/integrations/integrations-github-repos-query'
+import { useIntegrationsQuery } from 'data/integrations/integrations-query'
+import { useOrganizationsQuery } from 'data/organizations/organizations-query'
+import { useProjectsQuery } from 'data/projects/projects-query'
+import { EMPTY_ARR } from 'lib/void'
+import { useRouter } from 'next/router'
+import { useMemo } from 'react'
+import { NextPageWithLayout } from 'types'
+import { IconBook, IconLifeBuoy, LoadingLine } from 'ui'
+
+const GITHUB_ICON = (
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 98 96" className="w-6">
+ <path
+ fill="#ffffff"
+ fillRule="evenodd"
+ d="M48.854 0C21.839 0 0 22 0 49.217c0 21.756 13.993 40.172 33.405 46.69 2.427.49 3.316-1.059 3.316-2.362 0-1.141-.08-5.052-.08-9.127-13.59 2.934-16.42-5.867-16.42-5.867-2.184-5.704-5.42-7.17-5.42-7.17-4.448-3.015.324-3.015.324-3.015 4.934.326 7.523 5.052 7.523 5.052 4.367 7.496 11.404 5.378 14.235 4.074.404-3.178 1.699-5.378 3.074-6.6-10.839-1.141-22.243-5.378-22.243-24.283 0-5.378 1.94-9.778 5.014-13.2-.485-1.222-2.184-6.275.486-13.038 0 0 4.125-1.304 13.426 5.052a46.97 46.97 0 0 1 12.214-1.63c4.125 0 8.33.571 12.213 1.63 9.302-6.356 13.427-5.052 13.427-5.052 2.67 6.763.97 11.816.485 13.038 3.155 3.422 5.015 7.822 5.015 13.2 0 18.905-11.404 23.06-22.324 24.283 1.78 1.548 3.316 4.481 3.316 9.126 0 6.6-.08 11.897-.08 13.526 0 1.304.89 2.853 3.316 2.364 19.412-6.52 33.405-24.935 33.405-46.691C97.707 22 75.788 0 48.854 0z"
+ clipRule="evenodd"
+ />
+ </svg>
+)
+
+const ChooseProjectGitHubPage: NextPageWithLayout = () => {
+ const router = useRouter()
+ const { integrationId } = useParams()
+
+ const { data: integrations } = useIntegrationsQuery()
+ const { data: organizations } = useOrganizationsQuery()
+ const { data: allProjects } = useProjectsQuery()
+ const { data: allRepos } = useGitHubReposQuery({ integrationId })
+
+ const integration = integrations?.find((integration) => integration.id === integrationId)
+ const orgSlug = integration?.organization.slug
+ const organization = organizations?.find((organization) => organization.slug === orgSlug)
+ const projects = useMemo(
+ () =>
+ allProjects
+ ?.filter((project) => project.organization_id === organization?.id)
+ .map((project) => ({ id: project.id.toString(), name: project.name, ref: project.ref })) ??
+ EMPTY_ARR,
+ [allProjects, organization?.id]
+ )
+
+ const repos = useMemo(
+ () =>
+ allRepos?.map((repo) => ({
+ id: repo.id.toString(),
+ name: repo.full_name,
+ })) ?? EMPTY_ARR,
+ [allRepos]
+ )
+
+ const { mutate: createConnections, isLoading: isCreatingConnection } =
+ useIntegrationGitHubConnectionsCreateMutation({
+ onSuccess() {
+ router.push(`/org/${orgSlug}/integrations`)
+ },
+ })
+
+ return (
+ <>
+ <main className="overflow-auto flex flex-col h-full">
+ <LoadingLine loading={isCreatingConnection} />
+ <>
+ <ScaffoldContainer className="flex flex-col gap-6 grow py-8">
+ <header>
+ <h1 className="text-xl text-scale-1200">
+ Link a Supabase project to a GitHub repository
+ </h1>
+ <Markdown
+ className="text-scale-900"
+ // explain what this integration does
+ content={`
+This Supabase integration will allow you to link a Supabase project to a GitHub repository. This will allow you to deploy your database schema to your Supabase project.
+`}
+ />
+ </header>
+ <ProjectLinker
+ organizationIntegrationId={integration?.id}
+ foreignProjects={repos ?? EMPTY_ARR}
+ supabaseProjects={projects}
+ onCreateConnections={(vars) => {
+ createConnections(vars)
+ }}
+ installedConnections={integration?.connections}
+ isLoading={isCreatingConnection}
+ integrationIcon={GITHUB_ICON}
+ choosePrompt="Choose GitHub Repo"
+ />
+ </ScaffoldContainer>
+ </>
+
+ <ScaffoldDivider />
+ </main>
+ <ScaffoldContainer className="bg-body flex flex-row gap-6 py-6 border-t">
+ <div className="flex items-center gap-2 text-xs text-scale-900">
+ <IconBook size={16} /> Docs
+ </div>
+ <div className="flex items-center gap-2 text-xs text-scale-900">
+ <IconLifeBuoy size={16} /> Support
+ </div>
+ </ScaffoldContainer>
+ </>
+ )
+}
+
+ChooseProjectGitHubPage.getLayout = (page) => (
+ <GitHubIntegrationWindowLayout>{page}</GitHubIntegrationWindowLayout>
+)
+
+export default ChooseProjectGitHubPage
diff --git a/studio/pages/integrations/github/[slug]/choose-project.tsx b/studio/pages/integrations/github/[slug]/choose-project.tsx
deleted file mode 100644
index 056571b9458..00000000000
--- a/studio/pages/integrations/github/[slug]/choose-project.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import GitHubIntegrationWindowLayout from 'components/layouts/IntegrationsLayout/GitHubIntegrationWindowLayout'
-import { NextPageWithLayout } from 'types'
-
-const ChooseProjectGitHubPage: NextPageWithLayout = () => {
- return <div></div>
-}
-
-ChooseProjectGitHubPage.getLayout = (page) => (
- <GitHubIntegrationWindowLayout>{page}</GitHubIntegrationWindowLayout>
-)
-
-export default ChooseProjectGitHubPage
diff --git a/studio/pages/integrations/github/install.tsx b/studio/pages/integrations/github/install.tsx
index c0da8558089..4a70943340c 100644
--- a/studio/pages/integrations/github/install.tsx
+++ b/studio/pages/integrations/github/install.tsx
@@ -1,15 +1,15 @@
+import { useRouter } from 'next/router'
+import { useState } from 'react'
+
import { useParams } from 'common'
import { Markdown } from 'components/interfaces/Markdown'
import GitHubIntegrationWindowLayout from 'components/layouts/IntegrationsLayout/GitHubIntegrationWindowLayout'
-import IntegrationWindowLayout from 'components/layouts/IntegrationsLayout/IntegrationWindowLayout'
import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
import { useGitHubIntegrationCreateMutation } from 'data/integrations/github-integration-create-mutation'
import { useIntegrationsQuery } from 'data/integrations/integrations-query'
import { IntegrationName } from 'data/integrations/integrations.types'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
import { useStore } from 'hooks'
-import { useRouter } from 'next/router'
-import { useState } from 'react'
import { useGitHubIntegrationInstallationState } from 'state/github-integration-installation'
import { NextPageWithLayout, Organization } from 'types'
import { Alert, Badge, Button, IconBook, IconHexagon, IconLifeBuoy, Listbox, LoadingLine } from 'ui'
@@ -21,20 +21,10 @@ interface OrganizationsResponseWithInstalledData extends Organization {
installationInstalled?: boolean
}
-/**
- * Variations of the GitHub integration flow.
- * They require different UI and logic.
- *
- * Deploy Button - the flow that starts from the Deploy Button - https://github.com/docs/integrations#deploy-button
- * Marketplace - the flow that starts from the Marketplace - https://github.com/integrations
- *
- */
-export type GitHubIntegrationFlow = 'deploy-button' | 'marketing'
-
const GitHubIntegration: NextPageWithLayout = () => {
const router = useRouter()
const { ui } = useStore()
- const { code, installation_id: installationId } = useParams()
+ const { installation_id: installationId } = useParams()
const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null)
const [organizationIntegrationId, setOrganizationIntegrationId] = useState<string | null>(null)
@@ -45,7 +35,7 @@ const GitHubIntegration: NextPageWithLayout = () => {
*
* Array of integrations installed on all
*/
- const { data: integrationData, isLoading: integrationDataLoading } = useIntegrationsQuery()
+ const { data: integrationData } = useIntegrationsQuery()
const { data: organizationsData, isLoading: isLoadingOrganizationsQuery } = useOrganizationsQuery(
{
@@ -66,7 +56,9 @@ const GitHubIntegration: NextPageWithLayout = () => {
*/
const flatInstalledConnectionsIds: string[] | [] =
integrationData && integrationData.length > 0
- ? integrationData?.map((x) => x.organization.slug)
+ ? integrationData
+ .filter((x) => x.integration.name === 'Vercel')
+ .map((x) => x.organization.slug)
: []
/**
@@ -84,28 +76,15 @@ const GitHubIntegration: NextPageWithLayout = () => {
})
: []
- /**
- * Handle the correct route change based on wether the github integration
- * is following the 'marketplace' flow or 'deploy button' flow.
- *
- */
- function handleRouteChange() {
- const orgSlug = selectedOrg?.slug
-
- router.push({
- pathname: `/integrations/github/${orgSlug}/choose-project`,
- query: router.query,
- })
- }
-
const { mutate, isLoading: isLoadingGitHubIntegrationCreateMutation } =
useGitHubIntegrationCreateMutation({
onSuccess({ id }) {
- const orgSlug = selectedOrg?.slug
-
setOrganizationIntegrationId(id)
- handleRouteChange()
+ router.push({
+ pathname: `/integrations/github/${id}/choose-project`,
+ query: router.query,
+ })
},
onError(error: any) {
ui.setNotification({
@@ -118,18 +97,13 @@ const GitHubIntegration: NextPageWithLayout = () => {
function onInstall() {
const orgSlug = selectedOrg?.slug
- const isIntegrationInstalled = organizationsWithInstalledData.some(
- (x) => x.slug === orgSlug && x.installationInstalled
- )
+ const installedIntegration = integrationData?.find((x) => x.organization.slug === orgSlug)
+ const isIntegrationInstalled = Boolean(installedIntegration)
if (!orgSlug) {
return ui.setNotification({ category: 'error', message: 'Please select an organization' })
}
- if (!code) {
- return ui.setNotification({ category: 'error', message: 'GitHub code missing' })
- }
-
if (!installationId) {
return ui.setNotification({ category: 'error', message: 'GitHub Installation ID is missing' })
}
@@ -139,13 +113,15 @@ const GitHubIntegration: NextPageWithLayout = () => {
*/
if (!isIntegrationInstalled) {
mutate({
- code,
installationId,
orgSlug,
metadata: {},
})
} else {
- handleRouteChange()
+ router.push({
+ pathname: `/integrations/github/${installedIntegration?.id}/choose-project`,
+ query: router.query,
+ })
}
}
@@ -226,11 +202,9 @@ export interface OrganizationPickerProps {
const OrganizationPicker = ({
label = 'Choose an organization',
onSelectedOrgChange,
- integrationName,
dataLoading,
organizationsWithInstalledData,
}: OrganizationPickerProps) => {
- const { ui } = useStore()
const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null)
const { data, isLoading } = useOrganizationsQuery({
diff --git a/studio/pages/integrations/vercel.tsx b/studio/pages/integrations/vercel.tsx
deleted file mode 100644
index 29c927001cf..00000000000
--- a/studio/pages/integrations/vercel.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-import { useEffect } from 'react'
-
-import IntegrationWindowLayout from 'components/layouts/IntegrationsLayout/IntegrationWindowLayout'
-import { useRouter } from 'next/router'
-import { NextPageWithLayout } from 'types'
-
-const VercelIntegration: NextPageWithLayout = () => {
- const router = useRouter()
-
- useEffect(() => {
- router.push({ pathname: '/integrations/vercel/install', query: router.query })
- }, [router])
-
- return <></>
-}
-
-VercelIntegration.getLayout = (page) => <IntegrationWindowLayout>{page}</IntegrationWindowLayout>
-
-export default VercelIntegration
diff --git a/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx b/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
index 4465635cb5c..abf5107a1be 100644
--- a/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
+++ b/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
@@ -8,7 +8,7 @@ import { VercelIntegrationLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
import PasswordStrengthBar from 'components/ui/PasswordStrengthBar'
import { useProjectApiQuery } from 'data/config/project-api-query'
-import { useIntegrationConnectionsCreateMutation } from 'data/integrations/integration-connections-create-mutation'
+import { useIntegrationVercelConnectionsCreateMutation } from 'data/integrations/integrations-vercel-connections-create-mutation'
import { useIntegrationsQuery } from 'data/integrations/integrations-query'
import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
import { Integration } from 'data/integrations/integrations.types'
@@ -93,7 +93,7 @@ const CreateProject = ({
} = useParams()
const { mutateAsync: createConnections, isLoading: isLoadingCreateConnections } =
- useIntegrationConnectionsCreateMutation({})
+ useIntegrationVercelConnectionsCreateMutation()
const { data: organizationData, isLoading: isLoadingOrganizationsQuery } = useOrganizationsQuery()
diff --git a/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx b/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
index defe66f8310..8e2032902a6 100644
--- a/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
+++ b/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
@@ -1,23 +1,33 @@
-import { useMemo, useState } from 'react'
+import { keyBy } from 'lodash'
+import { useCallback, useMemo } from 'react'
import { useParams } from 'common'
-import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
+import ProjectLinker, { ForeignProject } from 'components/interfaces/Integrations/ProjectLinker'
import { Markdown } from 'components/interfaces/Markdown'
import { VercelIntegrationLayout } from 'components/layouts'
import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
+import { vercelIcon } from 'components/to-be-cleaned/ListIcons'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
+import { useIntegrationVercelConnectionsCreateMutation } from 'data/integrations/integrations-vercel-connections-create-mutation'
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'
+
+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()
- const [loading, setLoading] = useState<boolean>(false)
-
/**
* Fetch the list of organization based integration installations for Vercel.
*
@@ -45,7 +55,7 @@ const VercelIntegration: NextPageWithLayout = () => {
?.filter((project) => project.organization_id === organization?.id)
.map((project) => ({ id: project.id.toString(), name: project.name, ref: project.ref })) ??
EMPTY_ARR,
- [organizationSlug, supabaseProjectsData]
+ [organization?.id, supabaseProjectsData]
)
const { data: vercelProjectsData } = useVercelProjectsQuery(
@@ -56,11 +66,59 @@ const VercelIntegration: NextPageWithLayout = () => {
)
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 { mutate: createConnections, isLoading: isCreatingConnection } =
+ useIntegrationVercelConnectionsCreateMutation({
+ onSuccess() {
+ 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 (
<>
<main className="overflow-auto flex flex-col h-full">
- <LoadingLine loading={loading} />
+ <LoadingLine loading={isCreatingConnection} />
<>
<ScaffoldContainer className="flex flex-col gap-6 grow py-8">
<header>
@@ -70,7 +128,7 @@ const VercelIntegration: NextPageWithLayout = () => {
<Markdown
className="text-scale-900"
content={`
-This Supabase integration manages your envioemnt variables automatically to provide the latest keys in the unlikely event that you will need to refresh your JWT token.
+This Supabase integration manages your environment variables automatically to provide the latest keys in the unlikely event that you will need to refresh your JWT token.
`}
/>
</header>
@@ -78,13 +136,24 @@ This Supabase integration manages your envioemnt variables automatically to prov
organizationIntegrationId={integration?.id}
foreignProjects={vercelProjects}
supabaseProjects={supabaseProjects}
- onCreateConnections={() => {
- if (next) {
- window.location.href = next
- }
- }}
+ onCreateConnections={onCreateConnections}
installedConnections={integration?.connections}
- setLoading={setLoading}
+ isLoading={isCreatingConnection}
+ integrationIcon={VERCEL_ICON}
+ getForeignProjectIcon={getForeignProjectIcon}
+ choosePrompt="Choose Vercel Project"
+ />
+ <Markdown
+ content={`
+The following environment variables will be added:
+
+${ENV_VAR_RAW_KEYS.map((x) => {
+ return `
+ \n
+ - \`${x}\`
+`
+})}
+`}
/>
</ScaffoldContainer>
</>
diff --git a/studio/pages/integrations/vercel/install.tsx b/studio/pages/integrations/vercel/install.tsx
index dd629aed8b5..67016004b90 100644
--- a/studio/pages/integrations/vercel/install.tsx
+++ b/studio/pages/integrations/vercel/install.tsx
@@ -46,7 +46,7 @@ const VercelIntegration: NextPageWithLayout = () => {
*
* Array of integrations installed on all
*/
- const { data: integrationData, isLoading: integrationDataLoading } = useIntegrationsQuery()
+ const { data: integrationData } = useIntegrationsQuery()
const { data: organizationsData, isLoading: isLoadingOrganizationsQuery } = useOrganizationsQuery(
{
@@ -63,11 +63,12 @@ const VercelIntegration: NextPageWithLayout = () => {
/**
* Flat array of org slugs that have integration installed
- *
*/
const flatInstalledConnectionsIds: string[] | [] =
integrationData && integrationData.length > 0
- ? integrationData?.map((x) => x.organization.slug)
+ ? integrationData
+ .filter((x) => x.integration.name === 'Vercel')
+ .map((x) => x.organization.slug)
: []
/**