Skip to content

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

Wrap up github integration with branching

Joshen Limd2b7e3e40e50
diff --git a/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
index e2381426677..6b0a239d64a 100644
--- a/studio/components/interfaces/BranchManagement/BranchManagement.tsx
+++ b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
@@ -24,18 +24,20 @@ import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useBranchDeleteMutation } from 'data/branches/branch-delete-mutation'
import { useBranchesDisableMutation } from 'data/branches/branches-disable-mutation'
import { Branch, useBranchesQuery } from 'data/branches/branches-query'
-import { useSelectedProject, useStore } from 'hooks'
+import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
+import { useSelectedOrganization, useSelectedProject, useStore } from 'hooks'
+import { useAppUiStateSnapshot } from 'state/app'
import { MainBranchPanel } from './BranchPanels'
import CreateBranchSidePanel from './CreateBranchSidePanel'
import PreviewBranches from './PreviewBranches'
import PullRequests from './PullRequests'
-import { useAppUiStateSnapshot } from 'state/app'
const BranchManagement = () => {
const { ui } = useStore()
const router = useRouter()
const { ref } = useParams()
const projectDetails = useSelectedProject()
+ const selectedOrg = useSelectedOrganization()
// [Joshen TODO] To be dynamic
const isBranchingAllowed = true
@@ -50,6 +52,18 @@ const BranchManagement = () => {
const [showDisableBranching, setShowDisableBranching] = useState(false)
const [selectedBranchToDelete, setSelectedBranchToDelete] = useState<Branch>()
+ const { data: integrations, isLoading: isLoadingIntegrations } = useOrgIntegrationsQuery({
+ orgSlug: selectedOrg?.slug,
+ })
+ const githubIntegration = integrations?.find(
+ (integration) =>
+ integration.integration.name === 'GitHub' &&
+ integration.organization.slug === selectedOrg?.slug
+ )
+ const githubConnection = githubIntegration?.connections.find(
+ (connection) => connection.supabase_project_ref === ref
+ )
+
const { data: branches, error, isLoading, isError, isSuccess } = useBranchesQuery({ projectRef })
const [[mainBranch], previewBranches] = partition(branches, (branch) => branch.is_default)
@@ -79,6 +93,14 @@ const BranchManagement = () => {
},
})
+ const generatePullRequestURL = (branch?: string) => {
+ if (githubConnection === undefined) return 'https://github.com'
+
+ return branch !== undefined
+ ? `https://github.com/${githubConnection.metadata.name}/compare/${mainBranch.git_branch}...${branch}`
+ : `https://github.com/${githubConnection.metadata.name}/compare`
+ }
+
const onConfirmDeleteBranch = () => {
if (selectedBranchToDelete == undefined) return console.error('No branch selected')
if (projectRef == undefined) return console.error('Project ref is required')
@@ -146,12 +168,18 @@ const BranchManagement = () => {
{isSuccess && mainBranch !== undefined && (
<>
<MainBranchPanel
+ repo={githubConnection?.metadata.name}
branch={mainBranch}
onSelectDisableBranching={() => setShowDisableBranching(true)}
/>
- <PullRequests previewBranches={previewBranches} />
+ <PullRequests
+ previewBranches={previewBranches}
+ generatePullRequestURL={generatePullRequestURL}
+ />
<PreviewBranches
previewBranches={previewBranches}
+ generatePullRequestURL={generatePullRequestURL}
+ onSelectCreateBranch={() => setShowCreateBranch(true)}
onSelectDeleteBranch={setSelectedBranchToDelete}
/>
</>
diff --git a/studio/components/interfaces/BranchManagement/BranchPanels.tsx b/studio/components/interfaces/BranchManagement/BranchPanels.tsx
index f209176b6d9..6e7d661f2da 100644
--- a/studio/components/interfaces/BranchManagement/BranchPanels.tsx
+++ b/studio/components/interfaces/BranchManagement/BranchPanels.tsx
@@ -1,6 +1,8 @@
import clsx from 'clsx'
+import { useParams } from 'common'
import dayjs from 'dayjs'
import { noop } from 'lodash'
+import Link from 'next/link'
import { PropsWithChildren, forwardRef, useState } from 'react'
import {
Badge,
@@ -10,6 +12,7 @@ import {
DropdownMenuItem_Shadcn_,
DropdownMenuTrigger_Shadcn_,
DropdownMenu_Shadcn_,
+ IconExternalLink,
IconGitBranch,
IconGitHub,
IconMoreVertical,
@@ -18,18 +21,19 @@ import {
cn,
} from 'ui'
-import { useParams } from 'common'
import { Markdown } from 'components/interfaces/Markdown'
import { Branch } from 'data/branches/branches-query'
interface BranchPanelProps {
+ repo?: string
branch: Branch
onSelectUpdate?: () => void
onSelectDelete?: () => void
onSelectDisableBranching?: () => void
+ generatePullRequestURL?: (branch?: string) => string
}
-const MainBranchPanel = ({ branch, onSelectDisableBranching = noop }: BranchPanelProps) => {
+const MainBranchPanel = ({ repo, branch, onSelectDisableBranching = noop }: BranchPanelProps) => {
const { ref } = useParams()
const [open, setOpen] = useState(false)
const isActive = ref === branch.project_ref
@@ -42,6 +46,18 @@ const MainBranchPanel = ({ branch, onSelectDisableBranching = noop }: BranchPane
<IconGitHub size={18} strokeWidth={2} />
</div>
<p>Github branch workflow</p>
+ <Link passHref href={`https://github.com/${repo}`}>
+ <a target="_blank" rel="noreferrer">
+ <Button
+ type="text"
+ size="small"
+ className="text-light hover:text py-1 px-1.5"
+ iconRight={<IconExternalLink size={14} strokeWidth={1.5} />}
+ >
+ {repo}
+ </Button>
+ </a>
+ </Link>
</div>
</div>
<div className="bg-surface-100 border-t shadow-sm flex justify-between items-center pl-8 pr-6 py-3 rounded-b-lg text-sm">
@@ -95,7 +111,11 @@ const BranchContainer = ({ className, children }: PropsWithChildren<{ className?
)
}
-const BranchPanel = ({ branch, onSelectDelete = noop }: BranchPanelProps) => {
+const BranchPanel = ({
+ branch,
+ generatePullRequestURL,
+ onSelectDelete = noop,
+}: BranchPanelProps) => {
const { ref } = useParams()
const [open, setOpen] = useState(false)
@@ -104,6 +124,8 @@ const BranchPanel = ({ branch, onSelectDelete = noop }: BranchPanelProps) => {
const formattedTimeFromNow = dayjs(branch.created_at).fromNow()
const formattedCreatedAt = dayjs(branch.created_at).format('DD MMM YYYY, HH:mm:ss (ZZ)')
+ const pullRequestURL = generatePullRequestURL?.(branch.name) ?? 'https://github.com'
+
return (
<BranchContainer className="bg-surface-100">
<div className="flex items-center space-x-4">
@@ -114,7 +136,12 @@ const BranchPanel = ({ branch, onSelectDelete = noop }: BranchPanelProps) => {
{daysFromNow > 1 ? `Created on ${formattedCreatedAt}` : `Created ${formattedTimeFromNow}`}
</p>
</div>
- <div>
+ <div className="flex items-center space-x-4">
+ <Link passHref href={pullRequestURL}>
+ <a target="_blank" rel="noreferrer">
+ <Button>Create pull request</Button>
+ </a>
+ </Link>
<DropdownMenu_Shadcn_ open={open} onOpenChange={() => setOpen(!open)} modal={false}>
<DropdownMenuTrigger_Shadcn_>
<Button asChild type="text" className="px-1" icon={<IconMoreVertical size={14} />}>
diff --git a/studio/components/interfaces/BranchManagement/PreviewBranches.tsx b/studio/components/interfaces/BranchManagement/PreviewBranches.tsx
index 50003ddb270..5c83d0a5fa2 100644
--- a/studio/components/interfaces/BranchManagement/PreviewBranches.tsx
+++ b/studio/components/interfaces/BranchManagement/PreviewBranches.tsx
@@ -1,13 +1,21 @@
-import { Branch } from 'data/branches/branches-query'
import { Button, IconExternalLink, IconGitBranch } from 'ui'
+
+import { Branch } from 'data/branches/branches-query'
import { BranchContainer, BranchHeader, BranchPanel } from './BranchPanels'
interface PreviewBranchesProps {
previewBranches: Branch[]
+ generatePullRequestURL: (branch?: string) => string
+ onSelectCreateBranch: () => void
onSelectDeleteBranch: (branch: Branch) => void
}
-const PreviewBranches = ({ previewBranches, onSelectDeleteBranch }: PreviewBranchesProps) => {
+const PreviewBranches = ({
+ previewBranches,
+ generatePullRequestURL,
+ onSelectCreateBranch,
+ onSelectDeleteBranch,
+}: PreviewBranchesProps) => {
return (
<>
<BranchHeader markdown={previewBranches.length > 0 ? `#### Preview branches` : undefined} />
@@ -25,7 +33,9 @@ const PreviewBranches = ({ previewBranches, onSelectDeleteBranch }: PreviewBranc
<p className="text-scale-1000">Start developing in preview</p>
</div>
</div>
- <Button type="default">Create preview branch</Button>
+ <Button type="default" onClick={() => onSelectCreateBranch()}>
+ Create preview branch
+ </Button>
</div>
<div className="px-5 py-3 border-t flex items-center justify-between">
<div>
@@ -44,6 +54,7 @@ const PreviewBranches = ({ previewBranches, onSelectDeleteBranch }: PreviewBranc
<BranchPanel
key={branch.id}
branch={branch}
+ generatePullRequestURL={generatePullRequestURL}
onSelectDelete={() => onSelectDeleteBranch(branch)}
/>
))
diff --git a/studio/components/interfaces/BranchManagement/PullRequests.tsx b/studio/components/interfaces/BranchManagement/PullRequests.tsx
index 0e1fd0aeefd..fbcd4c6e84c 100644
--- a/studio/components/interfaces/BranchManagement/PullRequests.tsx
+++ b/studio/components/interfaces/BranchManagement/PullRequests.tsx
@@ -1,13 +1,17 @@
+import Link from 'next/link'
+import { Button, IconExternalLink, IconGitBranch } from 'ui'
+
import { Branch } from 'data/branches/branches-query'
import { BranchContainer, BranchHeader } from './BranchPanels'
-import { Button, IconExternalLink, IconGitBranch } from 'ui'
interface PullRequestsProps {
previewBranches: Branch[]
+ generatePullRequestURL: (branch?: string) => string
}
-const PullRequests = ({ previewBranches }: PullRequestsProps) => {
+const PullRequests = ({ previewBranches, generatePullRequestURL }: PullRequestsProps) => {
const pullRequests = []
+ const pullRequestUrl = generatePullRequestURL()
return (
<>
@@ -32,9 +36,13 @@ const PullRequests = ({ previewBranches }: PullRequestsProps) => {
<IconGitBranch strokeWidth={2} className="text-scale-1100" />
<p>Create a pull request</p>
</div>
- <Button type="default" iconRight={<IconExternalLink />}>
- Github
- </Button>
+ <Link passHref href={pullRequestUrl}>
+ <a target="_blank" rel="noreferrer">
+ <Button type="default" iconRight={<IconExternalLink />}>
+ Github
+ </Button>
+ </a>
+ </Link>
</div>
<div className="px-5 py-3 border-t flex items-center justify-between">
<div>
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
index 60f9711e0e6..a6c48cad0d4 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/BranchingWaitlistPopover.tsx
@@ -1,12 +1,12 @@
import Link from 'next/link'
import { useState } from 'react'
import {
- Popover_Shadcn_,
- PopoverTrigger_Shadcn_,
+ Badge,
Button,
IconGitBranch,
PopoverContent_Shadcn_,
- Badge,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
} from 'ui'
const BranchingWaitlistPopover = () => {
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
index a828a715e4a..41a4ae16676 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/EnableBranchingButton.tsx
@@ -1,17 +1,17 @@
import { useParams } from 'common'
-import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
-import { useSelectedOrganization, useStore } from 'hooks'
import { useEffect, useState } from 'react'
import { Button, IconFileText, IconGitBranch, Modal } from 'ui'
-import BranchingWaitlistPopover from './BranchingWaitlistPopover'
-import GithubRepositorySelection from './GithubRepositorySelection'
-import VercelProjectSelection from './VercelProjectSelection'
+
import SidePanelGitHubRepoLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelGitHubRepoLinker'
-import { IntegrationName } from 'data/integrations/integrations.types'
-import { useBranchCreateMutation } from 'data/branches/branch-create-mutation'
-import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import AlertError from 'components/ui/AlertError'
+import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { useBranchCreateMutation } from 'data/branches/branch-create-mutation'
+import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
+import { IntegrationName } from 'data/integrations/integrations.types'
+import { useSelectedOrganization, useStore } from 'hooks'
import { useAppUiStateSnapshot } from 'state/app'
+import BranchingWaitlistPopover from './BranchingWaitlistPopover'
+import GithubRepositorySelection from './GithubRepositorySelection'
const EnableBranchingButton = () => {
const { ui } = useStore()
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx
index 6915ce33b89..8df21d08933 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/GithubRepositorySelection.tsx
@@ -1,4 +1,5 @@
import clsx from 'clsx'
+import { useParams } from 'common'
import Link from 'next/link'
import { useRef, useState } from 'react'
import {
@@ -12,19 +13,15 @@ import {
Command_Shadcn_,
IconCheck,
IconChevronDown,
- IconGitHub,
Modal,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
Popover_Shadcn_,
- cn,
} from 'ui'
-import { useParams } from 'common'
import {
EmptyIntegrationConnection,
IntegrationConnection,
- IntegrationConnectionOption,
} from 'components/interfaces/Integrations/IntegrationPanels'
import AlertError from 'components/ui/AlertError'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
@@ -129,7 +126,7 @@ const GithubRepositorySelection = ({
type="default"
size="medium"
ref={comboBoxRef}
- className={cn(
+ className={clsx(
'justify-start w-64',
selectedBranch === undefined ? 'text-light' : 'text'
)}
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton/VercelProjectSelection.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton/VercelProjectSelection.tsx
index 1e0e50356f1..fcc4a3e6758 100644
--- a/studio/components/layouts/AppLayout/EnableBranchingButton/VercelProjectSelection.tsx
+++ b/studio/components/layouts/AppLayout/EnableBranchingButton/VercelProjectSelection.tsx
@@ -1,7 +1,8 @@
import { useParams } from 'common'
-import { Integration } from 'data/integrations/integrations.types'
import { Badge, Button, Modal } from 'ui'
+import { Integration } from 'data/integrations/integrations.types'
+
interface VercelProjectSelectionProps {
integration?: Integration
}