Skip to content

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

chore: remove github pull requests query (#21941)

Alaister Young0ea52ac2203a
diff --git a/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx
index 80caf03f0b8..717aa288833 100644
--- a/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/BranchManagement.tsx
@@ -12,7 +12,6 @@ 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 { useGitHubConnectionsQuery } from 'data/integrations/github-connections-query'
-import { useGitHubPullRequestsQuery } from 'data/integrations/github-pull-requests-query'
import { useSelectedOrganization, useSelectedProject } from 'hooks'
import {
AlertDescription_Shadcn_,
@@ -92,26 +91,10 @@ const BranchManagement = () => {
new Date(a.updated_at) < new Date(b.updated_at) ? 1 : -1
)
const branchesWithPRs = previewBranches.filter((branch) => branch.pr_number !== undefined)
- const prNumbers =
- branches !== undefined
- ? (branchesWithPRs.map((branch) => branch.pr_number).filter(Boolean) as number[])
- : undefined
const githubConnection = connections?.find((connection) => connection.project.ref === projectRef)
const repo = githubConnection?.repository.name ?? ''
- const {
- data: allPullRequests,
- error: pullRequestsError,
- isLoading: isLoadingPullRequests,
- isError: isErrorPullRequests,
- isSuccess: isSuccessPullRequests,
- } = useGitHubPullRequestsQuery({
- connectionId: githubConnection?.id,
- prNumbers,
- })
- const pullRequests = allPullRequests ?? []
-
const isError = isErrorConnections || isErrorBranches
const isLoading = isLoadingConnections || isLoadingBranches
const isSuccess = isSuccessConnections && isSuccessBranches
@@ -276,7 +259,6 @@ const BranchManagement = () => {
repo={repo}
mainBranch={mainBranch}
previewBranches={previewBranches}
- pullRequests={pullRequests}
onViewAllBranches={() => setView('branches')}
onSelectCreateBranch={() => setShowCreateBranch(true)}
onSelectDeleteBranch={setSelectedBranchToDelete}
@@ -287,38 +269,23 @@ const BranchManagement = () => {
<BranchManagementSection
header={`${branchesWithPRs.length} branches with pull requests found`}
>
- {isLoadingPullRequests && <BranchLoader />}
- {isErrorPullRequests && (
- <AlertError
- error={pullRequestsError}
- subject="Failed to retrieve GitHub pull requests"
- />
- )}
- {isSuccessPullRequests && (
- <>
- {branchesWithPRs.length > 0 ? (
- branchesWithPRs.map((branch) => {
- const pullRequest = pullRequests?.find(
- (pr) => pr.branch === branch.git_branch && pr.repo === repo
- )
- return (
- <BranchRow
- key={branch.id}
- repo={repo}
- branch={branch}
- pullRequest={pullRequest}
- generateCreatePullRequestURL={generateCreatePullRequestURL}
- onSelectDeleteBranch={() => setSelectedBranchToDelete(branch)}
- />
- )
- })
- ) : (
- <PullRequestsEmptyState
- url={generateCreatePullRequestURL()}
- hasBranches={previewBranches.length > 0}
+ {branchesWithPRs.length > 0 ? (
+ branchesWithPRs.map((branch) => {
+ return (
+ <BranchRow
+ key={branch.id}
+ repo={repo}
+ branch={branch}
+ generateCreatePullRequestURL={generateCreatePullRequestURL}
+ onSelectDeleteBranch={() => setSelectedBranchToDelete(branch)}
/>
- )}
- </>
+ )
+ })
+ ) : (
+ <PullRequestsEmptyState
+ url={generateCreatePullRequestURL()}
+ hasBranches={previewBranches.length > 0}
+ />
)}
</BranchManagementSection>
)}
@@ -338,15 +305,11 @@ const BranchManagement = () => {
)}
{isSuccessBranches &&
previewBranches.map((branch) => {
- const pullRequest = pullRequests?.find(
- (pr) => pr.branch === branch.git_branch && pr.repo === repo
- )
return (
<BranchRow
key={branch.id}
repo={repo}
branch={branch}
- pullRequest={pullRequest}
generateCreatePullRequestURL={generateCreatePullRequestURL}
onSelectDeleteBranch={() => setSelectedBranchToDelete(branch)}
/>
diff --git a/apps/studio/components/interfaces/BranchManagement/BranchPanels.tsx b/apps/studio/components/interfaces/BranchManagement/BranchPanels.tsx
index 27566b81a47..8c573523dd2 100644
--- a/apps/studio/components/interfaces/BranchManagement/BranchPanels.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/BranchPanels.tsx
@@ -8,7 +8,6 @@ import { useInView } from 'react-intersection-observer'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { useBranchQuery } from 'data/branches/branch-query'
import type { Branch } from 'data/branches/branches-query'
-import type { GitHubPullRequest } from 'data/integrations/github-pull-requests-query'
import {
Badge,
Button,
@@ -76,7 +75,6 @@ interface BranchRowProps {
repo: string
branch: Branch
isMain?: boolean
- pullRequest?: GitHubPullRequest
generateCreatePullRequestURL?: (branchName?: string) => string
onSelectDeleteBranch: () => void
}
@@ -85,7 +83,6 @@ export const BranchRow = ({
branch,
isMain = false,
repo,
- pullRequest,
generateCreatePullRequestURL,
onSelectDeleteBranch,
}: BranchRowProps) => {
@@ -138,10 +135,10 @@ export const BranchRow = ({
</p>
</div>
<div className="flex items-center gap-x-8">
- {pullRequest !== undefined && (
+ {branch.pr_number !== undefined && (
<div className="flex items-center">
<Link
- href={pullRequest.url}
+ href={`https://github.com/${repo}/pull/${branch.pr_number}`}
target="_blank"
rel="noreferrer"
className="text-xs transition text-foreground-lighter mr-4 hover:text-foreground"
@@ -158,9 +155,9 @@ export const BranchRow = ({
passHref
target="_blank"
rel="noreferer"
- href={`http://github.com/${pullRequest.target.repo}/tree/${pullRequest.target.branch}`}
+ href={`http://github.com/${repo}/tree/${branch.git_branch}`}
>
- {pullRequest.target.branch}
+ {branch.git_branch}
</Link>
</Button>
</div>
@@ -193,7 +190,11 @@ export const BranchRow = ({
passHref
target="_blank"
rel="noreferrer"
- href={pullRequest?.url ?? createPullRequestURL}
+ href={
+ branch.pr_number !== undefined
+ ? `https://github.com/${repo}/pull/${branch.pr_number}`
+ : createPullRequestURL
+ }
>
{branch.pr_number !== undefined ? 'View Pull Request' : 'Create Pull Request'}
</Link>
diff --git a/apps/studio/components/interfaces/BranchManagement/Overview.tsx b/apps/studio/components/interfaces/BranchManagement/Overview.tsx
index 01dd04d28a6..74d192c51b1 100644
--- a/apps/studio/components/interfaces/BranchManagement/Overview.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/Overview.tsx
@@ -2,7 +2,6 @@ import { noop } from 'lodash'
import { Button, IconChevronRight } from 'ui'
import type { Branch } from 'data/branches/branches-query'
-import type { GitHubPullRequest } from 'data/integrations/github-pull-requests-query'
import { BranchLoader, BranchManagementSection, BranchRow, BranchRowLoader } from './BranchPanels'
import { PreviewBranchesEmptyState } from './EmptyStates'
@@ -14,7 +13,6 @@ interface OverviewProps {
repo: string
mainBranch: Branch
previewBranches: Branch[]
- pullRequests: GitHubPullRequest[]
onViewAllBranches: () => void
onSelectCreateBranch: () => void
onSelectDeleteBranch: (branch: Branch) => void
@@ -27,7 +25,6 @@ const Overview = ({
repo,
mainBranch,
previewBranches,
- pullRequests,
onViewAllBranches,
onSelectCreateBranch,
onSelectDeleteBranch,
@@ -64,15 +61,11 @@ const Overview = ({
)}
{isSuccess &&
previewBranches.slice(0, MAX_BRANCHES_OVERVIEW).map((branch) => {
- const pullRequest = pullRequests?.find(
- (pr) => pr.branch === branch.git_branch && pr.repo === repo
- )
return (
<BranchRow
key={branch.id}
repo={repo}
branch={branch}
- pullRequest={pullRequest}
generateCreatePullRequestURL={generateCreatePullRequestURL}
onSelectDeleteBranch={() => onSelectDeleteBranch(branch)}
/>
diff --git a/apps/studio/data/integrations/github-pull-requests-query.ts b/apps/studio/data/integrations/github-pull-requests-query.ts
deleted file mode 100644
index 6adfbeaa95d..00000000000
--- a/apps/studio/data/integrations/github-pull-requests-query.ts
+++ /dev/null
@@ -1,54 +0,0 @@
-import { useQuery, UseQueryOptions } from '@tanstack/react-query'
-import { get } from 'data/fetchers'
-import { integrationKeys } from './keys'
-import type { ResponseError } from 'types'
-import type { components } from 'data/api'
-
-export type GitHubPullRequestsVariables = {
- connectionId?: number
- prNumbers?: number[]
-}
-
-// TODO(alaister): find the actual type
-export type GitHubPullRequest = any
-
-export async function getGitHubPullRequests(
- { connectionId, prNumbers = [] }: GitHubPullRequestsVariables,
- signal?: AbortSignal
-) {
- if (!connectionId) throw new Error('connectionId is required')
-
- const { data, error } = await get(`/platform/integrations/github/pull-requests/{connectionId}`, {
- params: {
- path: {
- connectionId,
- },
- query: {
- pr_number: prNumbers,
- },
- },
- signal,
- })
-
- if (error) throw error
- return data
-}
-
-export type GitHubPullRequestsData = Awaited<ReturnType<typeof getGitHubPullRequests>>
-export type GitHubPullRequestsError = ResponseError
-
-export const useGitHubPullRequestsQuery = <TData = GitHubPullRequestsData>(
- { connectionId, prNumbers }: GitHubPullRequestsVariables,
- {
- enabled = true,
- ...options
- }: UseQueryOptions<GitHubPullRequestsData, GitHubPullRequestsError, TData> = {}
-) =>
- useQuery<GitHubPullRequestsData, GitHubPullRequestsError, TData>(
- integrationKeys.githubPullRequestsList(connectionId, prNumbers),
- ({ signal }) => getGitHubPullRequests({ connectionId, prNumbers }, signal),
- {
- enabled: enabled && typeof connectionId !== 'undefined',
- ...options,
- }
- )
diff --git a/apps/studio/data/integrations/keys.ts b/apps/studio/data/integrations/keys.ts
index fd30674f139..71ac8bea3ad 100644
--- a/apps/studio/data/integrations/keys.ts
+++ b/apps/studio/data/integrations/keys.ts
@@ -22,11 +22,6 @@ export const integrationKeys = {
githubAuthorization: () => ['github-authorization'] as const,
githubRepositoriesList: () => ['github-repositories'] as const,
githubBranchesList: (connectionId: number | undefined) => ['github-branches', connectionId],
- githubPullRequestsList: (connectionId: number | undefined, prNumbers: number[] | undefined) => [
- 'github-pull-requests',
- connectionId,
- { prNumbers },
- ],
githubConnectionsList: (organizationId: number | undefined) =>
['organizations', organizationId, 'github-connections'] as const,
}