Skip to content

Commit

Permalink
Integrate updated GH PR endpoint (supabase#18774)
Browse files Browse the repository at this point in the history
* Integrate updated GH PR endpoint

* Address comments
  • Loading branch information
joshenlim committed Nov 10, 2023
1 parent b89c4d2 commit 01408f7
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ const BranchManagement = () => {
} = useBranchesQuery({ projectRef })
const [[mainBranch], previewBranches] = partition(branches, (branch) => branch.is_default)
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 githubIntegration = integrations?.find(
(integration) =>
Expand All @@ -92,7 +96,7 @@ const BranchManagement = () => {
organizationIntegrationId: githubIntegration?.id,
repoOwner,
repoName,
target: mainBranch?.git_branch,
prNumbers,
})
const pullRequests = allPullRequests ?? []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export const BranchRow = ({
</Button>
</div>
)}

{isMain ? (
<div className="flex items-center gap-x-2">
<Button asChild type="default" iconRight={<IconExternalLink />}>
Expand Down
39 changes: 0 additions & 39 deletions studio/data/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4763,40 +4763,6 @@ export interface components {
extensionId: string
items: components['schemas']['ResourceBillingItem'][]
}
ResourceProvisioningBody: {
/** @description A UNIX epoch timestamp value */
timestamp: number
/** @description A random unique string identifying the individual request */
nonce: string
/** @description The full request target URL */
url: string
/** @description Name of the extension */
name: string
/** @description Unique ID representing the extension */
id: string
/** @description Unique ID representing an organization */
organization_id: string
/** @description Display name for an organization */
organization_name: string
/** @description Obfuscated email that routes to all organization admins */
organization_email: string
/** @description Obfuscated email that routes to the provisioning user */
user_email: string
/** @description Unique ID representing an user */
user_id: string
/** @description The three-letter, primary Fly.io region where the target app intends to write from */
primary_region: string
/** @description An IPv6 address on the customer network assigned to this extension */
ip_address: string
/**
* @description An array of Fly.io region codes where read replicas should be provisioned
* @default []
*/
read_regions: string[]
/** @description Database password (Optional, don't send to generate one) */
db_pass?: string
user_name: string
}
ResourceProvisioningConfigResponse: {
/**
* @description PSQL connection string
Expand Down Expand Up @@ -12340,11 +12306,6 @@ export interface operations {
}
/** Creates a database */
ExtensionsController_provisionResource: {
requestBody: {
content: {
'application/json': components['schemas']['ResourceProvisioningBody']
}
}
responses: {
201: {
content: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,30 @@ export type GithubPullRequestsVariables = {
organizationIntegrationId?: string
repoOwner: string
repoName: string
target?: string
prNumbers?: number[]
}

export type GitHubPullRequest = components['schemas']['GetGithubPullRequest']

export async function getGitHubPullRequests(
{ organizationIntegrationId, repoOwner, repoName, target }: GithubPullRequestsVariables,
{ organizationIntegrationId, repoOwner, repoName, prNumbers }: GithubPullRequestsVariables,
signal?: AbortSignal
) {
if (!organizationIntegrationId) throw new Error('Organization integration ID is required')
if (!target) throw new Error('Target branch is required')
if (!prNumbers) throw new Error('A list of PR numbers is required')

const { data, error } = await get(
`/platform/integrations/github/pull-requests/{organization_integration_id}/{repo_owner}/{repo_name}/{target}`,
`/platform/integrations/github/pull-requests/{organization_integration_id}/{repo_owner}/{repo_name}`,
{
params: {
path: {
organization_integration_id: organizationIntegrationId,
repo_owner: repoOwner,
repo_name: repoName,
target,
},
query: {
// @ts-ignore generated api types is incorrect here, to remove ignore statement once fixed
pr_number: prNumbers,
},
},
signal,
Expand All @@ -43,23 +46,24 @@ export type GithubPullRequestsData = Awaited<ReturnType<typeof getGitHubPullRequ
export type GithubPullRequestsError = ResponseError

export const useGithubPullRequestsQuery = <TData = GithubPullRequestsData>(
{ organizationIntegrationId, repoOwner, repoName, target }: GithubPullRequestsVariables,
{ organizationIntegrationId, repoOwner, repoName, prNumbers }: GithubPullRequestsVariables,
{
enabled = true,
...options
}: UseQueryOptions<GithubPullRequestsData, GithubPullRequestsError, TData> = {}
) =>
useQuery<GithubPullRequestsData, GithubPullRequestsError, TData>(
integrationKeys.githubPullRequestsList(organizationIntegrationId, repoOwner, repoName, target),
// [Joshen] Just fyi im not sure if we need to include prNumber in the RQ key here
integrationKeys.githubPullRequestsList(organizationIntegrationId, repoOwner, repoName),
({ signal }) =>
getGitHubPullRequests({ organizationIntegrationId, repoOwner, repoName, target }, signal),
getGitHubPullRequests({ organizationIntegrationId, repoOwner, repoName, prNumbers }, signal),
{
enabled:
enabled &&
typeof organizationIntegrationId !== 'undefined' &&
typeof repoOwner !== 'undefined' &&
typeof repoName !== 'undefined' &&
typeof target !== 'undefined',
typeof prNumbers !== 'undefined',
...options,
}
)
12 changes: 2 additions & 10 deletions studio/data/integrations/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ export const integrationKeys = {
githubPullRequestsList: (
organization_integration_id: string | undefined,
repo_owner: string,
repo_name: string,
target: string | undefined
) => [
'organizations',
organization_integration_id,
'pull-requests',
repo_owner,
repo_name,
target,
],
repo_name: string
) => ['organizations', organization_integration_id, 'pull-requests', repo_owner, repo_name],
githubConnectionsList: (organization_integration_id: string | undefined) =>
['organizations', organization_integration_id, 'github-connections'] as const,
}

0 comments on commit 01408f7

Please sign in to comment.