Skip to content

Commit

Permalink
fix: use private org for location when set
Browse files Browse the repository at this point in the history
  • Loading branch information
sutterj committed Jun 17, 2024
1 parent 4c7aad0 commit 594ba83
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 10 deletions.
24 changes: 18 additions & 6 deletions src/app/[organizationId]/forks/[forkId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,16 @@ const Fork = () => {
const start = pageIndex * pageSize
const end = start + pageSize

const {
data: getConfigData,
isLoading: configLoading,
error: configError,
} = trpc.getConfig.useQuery({
orgId: organizationId as string,
})

const orgName = getConfigData?.privateOrg ?? orgData?.login

const {
data: createMirrorData,
isLoading: createMirrorLoading,
Expand Down Expand Up @@ -267,7 +277,7 @@ const Fork = () => {
await deleteMirror({
mirrorName,
orgId: String(orgData?.id),
orgName: orgData?.name ?? '',
orgName: orgName ?? '',
}).then((res) => {
if (!res.success) {
openDeleteErrorFlash()
Expand All @@ -287,7 +297,7 @@ const Fork = () => {
)

// show loading table
if (!mirrors || mirrorsLoading) {
if (!mirrors || mirrorsLoading || configLoading) {
return (
<Box>
<ForkHeader forkData={forkData} />
Expand Down Expand Up @@ -361,6 +371,9 @@ const Fork = () => {
<Box sx={{ marginBottom: '10px' }}>
{deleteMirrorLoading && <Loading message="Deleting mirror..." />}
</Box>
<Box sx={{ marginBottom: '10px' }}>
{configError && <ErrorFlash message={configError.message} />}
</Box>
<Box sx={{ marginBottom: '10px' }}>
{listMirrorsError && <ErrorFlash message={listMirrorsError.message} />}
</Box>
Expand Down Expand Up @@ -549,15 +562,15 @@ const Fork = () => {
</Table.Container>
)}
<CreateMirrorDialog
orgLogin={orgData?.login as string}
orgLogin={orgName ?? ''}
forkParentName={forkData?.parent?.name as string}
forkParentOwnerLogin={forkData?.parent?.owner.login as string}
closeDialog={closeCreateDialog}
isOpen={isCreateDialogOpen}
createMirror={handleOnCreateMirror}
/>
<EditMirrorDialog
orgLogin={orgData?.login as string}
orgLogin={orgName ?? ''}
forkParentName={forkData?.parent?.name as string}
forkParentOwnerLogin={forkData?.parent?.owner.login as string}
orgId={organizationId as string}
Expand All @@ -567,9 +580,8 @@ const Fork = () => {
editMirror={handleOnEditMirror}
/>
<DeleteMirrorDialog
orgLogin={orgData?.login as string}
orgLogin={orgName ?? ''}
orgId={organizationId as string}
orgName={orgData?.name as string}
mirrorName={deleteMirrorName as string}
closeDialog={closeDeleteDialog}
isOpen={Boolean(deleteMirrorName)}
Expand Down
2 changes: 2 additions & 0 deletions src/app/api/trpc/trpc-router.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import configRouter from 'server/config/router'
import gitRouter from '../../../server/git/router'
import octokitRouter from '../../../server/octokit/router'
import reposRouter from '../../../server/repos/router'
Expand All @@ -13,6 +14,7 @@ export const appRouter = t.mergeRouters(
reposRouter,
octokitRouter,
gitRouter,
configRouter,
healthCheckerRouter,
)

Expand Down
6 changes: 2 additions & 4 deletions src/app/components/dialog/DeleteMirrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import { Dialog } from '@primer/react/lib-esm/drafts'
interface DeleteMirrorDialogProps {
orgLogin: string
orgId: string
orgName: string
mirrorName: string
isOpen: boolean
closeDialog: () => void
deleteMirror: (data: {
orgId: string
orgName: string
orgLogin: string
mirrorName: string
}) => void
}

export const DeleteMirrorDialog = ({
orgLogin,
orgId,
orgName,
mirrorName,
isOpen,
closeDialog,
Expand All @@ -36,7 +34,7 @@ export const DeleteMirrorDialog = ({
{
content: 'Delete',
variant: 'danger',
onClick: () => deleteMirror({ orgId, orgName, mirrorName }),
onClick: () => deleteMirror({ orgId, orgLogin, mirrorName }),
},
]}
onClose={closeDialog}
Expand Down
30 changes: 30 additions & 0 deletions src/server/config/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { TRPCError } from '@trpc/server'
import { getConfig } from '../../bot/config'
import { logger } from '../../utils/logger'
import { GetConfigSchema } from './schema'

const configApiLogger = logger.getSubLogger({ name: 'org-api' })

// Get the config values for the given org
export const getConfigHandler = async ({
input,
}: {
input: GetConfigSchema
}) => {
try {
configApiLogger.info('Fetching config', { ...input })

const config = await getConfig(input.orgId)

configApiLogger.debug('Fetched config', config)

return config
} catch (error) {
configApiLogger.error('Error fetching config', { error })

throw new TRPCError({
code: 'INTERNAL_SERVER_ERROR',
message: (error as Error).message,
})
}
}
11 changes: 11 additions & 0 deletions src/server/config/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { procedure, router } from '../../utils/trpc-server'
import { getConfigHandler } from './controller'
import { GetConfigSchema } from './schema'

const configRouter = router({
getConfig: procedure
.input(GetConfigSchema)
.query(({ input }) => getConfigHandler({ input })),
})

export default configRouter
7 changes: 7 additions & 0 deletions src/server/config/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { z } from 'zod'

export const GetConfigSchema = z.object({
orgId: z.string(),
})

export type GetConfigSchema = z.TypeOf<typeof GetConfigSchema>

0 comments on commit 594ba83

Please sign in to comment.