Skip to content

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

adds SidePanelGitHubRepoLinker

Alaister Young0e7b1f4f61f0
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
index d3091a75519..73ecdfb1e36 100644
--- a/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
+++ b/studio/components/interfaces/Organization/IntegrationSettings/IntegrationSettings.tsx
@@ -4,6 +4,7 @@ import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-pr
import { useSelectedOrganization } from 'hooks'
import { getVercelConfigurationUrl } from 'lib/integration-utils'
import Integration from './Integration'
+import SidePanelGitHubRepoLinker from './SidePanelGitHubRepoLinker'
import SidePanelVercelProjectLinker from './SidePanelVercelProjectLinker'
const IntegrationSettings = () => {
@@ -87,6 +88,7 @@ These connections will be part of a GitHub workflow that is currently in develop
integrations={githubIntegrations}
/>
<SidePanelVercelProjectLinker />
+ <SidePanelGitHubRepoLinker />
</>
)
}
diff --git a/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsx b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsx
new file mode 100644
index 00000000000..4ff69b1585e
--- /dev/null
+++ b/studio/components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker.tsx
@@ -0,0 +1,130 @@
+import { useCallback, useMemo } from 'react'
+
+import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
+import { Markdown } from 'components/interfaces/Markdown'
+import { useIntegrationGitHubConnectionsCreateMutation } from 'data/integrations/integrations-github-connections-create-mutation'
+import { useGitHubReposQuery } from 'data/integrations/integrations-github-repos-query'
+import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
+import { useProjectsQuery } from 'data/projects/projects-query'
+import { useSelectedOrganization } from 'hooks'
+import { EMPTY_ARR } from 'lib/void'
+import { useGithubConnectionConfigPanelSnapshot } from 'state/github-connection-config-panel'
+import { SidePanel } 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 SidePanelGitHubRepoLinker = () => {
+ const selectedOrganization = useSelectedOrganization()
+
+ const { data: integrationData } = useOrgIntegrationsQuery({
+ orgSlug: selectedOrganization?.slug,
+ })
+ const githubIntegrations = integrationData?.filter(
+ (integration) => integration.integration.name === 'GitHub'
+ ) // github
+
+ const snapshot = useGithubConnectionConfigPanelSnapshot()
+
+ /**
+ * Find the right integration
+ *
+ * we use the snapshot.organizationIntegrationId which should be set whenever this sidepanel is opened
+ */
+ const selectedIntegration = githubIntegrations?.find(
+ (x) => x.id === snapshot.organizationIntegrationId
+ )
+
+ const organizationIntegrationId = snapshot.organizationIntegrationId
+ const open = snapshot.open
+
+ /**
+ * Supabase projects available
+ */
+ const { data: supabaseProjectsData } = useProjectsQuery({
+ enabled: organizationIntegrationId !== undefined,
+ })
+
+ const supabaseProjects = useMemo(
+ () =>
+ supabaseProjectsData
+ ?.filter((project) => project.organization_id === selectedOrganization?.id)
+ .map((project) => ({ id: project.id.toString(), name: project.name, ref: project.ref })) ??
+ EMPTY_ARR,
+ [selectedOrganization?.id, supabaseProjectsData]
+ )
+
+ const { data: githubProjectsData } = useGitHubReposQuery(
+ {
+ integrationId: organizationIntegrationId,
+ },
+ { enabled: organizationIntegrationId !== undefined }
+ )
+
+ const githubRepos = useMemo(
+ () =>
+ githubProjectsData?.map((repo) => ({
+ id: repo.id.toString(),
+ name: repo.full_name,
+ })) ?? EMPTY_ARR,
+ [githubProjectsData]
+ )
+
+ const { mutate: createConnections, isLoading: isCreatingConnection } =
+ useIntegrationGitHubConnectionsCreateMutation({
+ onSuccess() {
+ snapshot.setOpen(false)
+ },
+ })
+
+ const onCreateConnections = useCallback(
+ (vars) => {
+ createConnections(vars)
+ },
+ [createConnections]
+ )
+
+ return (
+ <SidePanel
+ header={'Add GitHub repository'}
+ size="large"
+ visible={open}
+ hideFooter
+ onCancel={() => snapshot.setOpen(false)}
+ >
+ <div className="py-10 flex flex-col gap-6 bg-body h-full">
+ <SidePanel.Content>
+ <Markdown
+ content={`
+### Choose repository to connect to
+
+Check the details below before proceeding
+ `}
+ />
+ </SidePanel.Content>
+ <SidePanel.Content className="flex flex-col gap-2">
+ <ProjectLinker
+ organizationIntegrationId={selectedIntegration?.id}
+ foreignProjects={githubRepos}
+ supabaseProjects={supabaseProjects}
+ onCreateConnections={onCreateConnections}
+ installedConnections={selectedIntegration?.connections}
+ isLoading={isCreatingConnection}
+ integrationIcon={GITHUB_ICON}
+ choosePrompt="Choose GitHub Repo"
+ />
+ </SidePanel.Content>
+ </div>
+ </SidePanel>
+ )
+}
+
+export default SidePanelGitHubRepoLinker
diff --git a/studio/data/api.d.ts b/studio/data/api.d.ts
index 57c1537e7bf..88909a8dd2a 100644
--- a/studio/data/api.d.ts
+++ b/studio/data/api.d.ts
@@ -704,6 +704,29 @@ 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
+ */
+ 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"];
+ };
"/system/auth/{ref}/templates/{template}": {
/** Gets GoTrue template */
get: operations["AuthTemplateController_getTemplate"];
@@ -2449,9 +2472,6 @@ export interface components {
packagePrice: number;
freeUnits?: number;
};
- BillingPricingOptionsNone: {
- freeUnits?: number;
- };
BillingUsageBasedPrice: {
/** @enum {string} */
metric: "EGRESS" | "DATABASE_EGRESS" | "DATABASE_SIZE" | "STORAGE_EGRESS" | "STORAGE_SIZE" | "MONTHLY_ACTIVE_USERS" | "MONTHLY_ACTIVE_SSO_USERS" | "FUNCTION_INVOCATIONS" | "FUNCTION_COUNT" | "STORAGE_IMAGES_TRANSFORMED" | "REALTIME_MESSAGE_COUNT" | "REALTIME_PEAK_CONNECTIONS" | "COMPUTE_HOURS_XS" | "COMPUTE_HOURS_SM" | "COMPUTE_HOURS_MD" | "COMPUTE_HOURS_L" | "COMPUTE_HOURS_XL" | "COMPUTE_HOURS_2XL" | "COMPUTE_HOURS_4XL" | "COMPUTE_HOURS_8XL" | "COMPUTE_HOURS_12XL" | "COMPUTE_HOURS_16XL";
@@ -3723,6 +3743,27 @@ export interface components {
organization_integration_id: string;
connection: components["schemas"]["IntegrationConnection"];
};
+ 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"];
+ };
FunctionResponse: {
id: string;
slug: string;
@@ -8132,6 +8173,82 @@ 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
+ */
+ 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 GoTrue template */
AuthTemplateController_getTemplate: {
parameters: {
diff --git a/studio/data/integrations/github-integration-create-mutation.ts b/studio/data/integrations/github-integration-create-mutation.ts
index 8ae13f84b94..668e2880e4b 100644
--- a/studio/data/integrations/github-integration-create-mutation.ts
+++ b/studio/data/integrations/github-integration-create-mutation.ts
@@ -1,10 +1,10 @@
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'
export type GitHubIntegrationCreateVariables = {
- installationId: string
+ installationId: number
orgSlug: string
metadata: { [key: string]: string }
}
@@ -14,16 +14,16 @@ export async function createGitHubIntegration({
orgSlug,
metadata,
}: GitHubIntegrationCreateVariables) {
- const response = await post(`${API_URL}/integrations/github`, {
- installation_id: installationId,
- organization_slug: orgSlug,
- metadata,
+ const { data, error } = await post('/platform/integrations/github', {
+ body: {
+ installation_id: installationId,
+ organization_slug: orgSlug,
+ metadata: metadata as any,
+ },
})
- if (response.error) {
- throw response.error
- }
+ if (error) throw error
- return response
+ return data
}
type GitHubIntegrationCreateData = Awaited<ReturnType<typeof createGitHubIntegration>>
@@ -43,7 +43,7 @@ export const useGitHubIntegrationCreateMutation = ({
await Promise.all([
queryClient.invalidateQueries(integrationKeys.integrationsList()),
queryClient.invalidateQueries(integrationKeys.integrationsListWithOrg(variables.orgSlug)),
- // queryClient.invalidateQueries(integrationKeys.githubProjectList(data.id)),
+ queryClient.invalidateQueries(integrationKeys.githubRepoList(data.id)),
])
await onSuccess?.(data, variables, context)
},
diff --git a/studio/pages/integrations/github/install.tsx b/studio/pages/integrations/github/install.tsx
index 4a70943340c..1d0637d223f 100644
--- a/studio/pages/integrations/github/install.tsx
+++ b/studio/pages/integrations/github/install.tsx
@@ -113,7 +113,7 @@ const GitHubIntegration: NextPageWithLayout = () => {
*/
if (!isIntegrationInstalled) {
mutate({
- installationId,
+ installationId: Number(installationId),
orgSlug,
metadata: {},
})