Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable mirroring non-forked repos #252

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const env = createEnv({
// Optional environment variables
LOGGING_LEVEL: z.string().optional().default('debug'),
NODE_ENV: z.string().optional().default('development'),
FORKS_ONLY: z.string().optional().default('true'),
PUBLIC_ORG: z.string().optional(),
PRIVATE_ORG: z.string().optional(),
// Custom validation for a comma separated list of strings
Expand Down Expand Up @@ -62,6 +63,7 @@ export const env = createEnv({
PRIVATE_KEY: process.env.PRIVATE_KEY,
LOGGING_LEVEL: process.env.LOGGING_LEVEL,
NODE_ENV: process.env.NODE_ENV,
FORKS_ONLY: process.env.FORKS_ONLY,
PUBLIC_ORG: process.env.PUBLIC_ORG,
PRIVATE_ORG: process.env.PRIVATE_ORG,
ALLOWED_HANDLES: process.env.ALLOWED_HANDLES,
Expand Down
14 changes: 10 additions & 4 deletions src/hooks/useForks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ import { logger } from '../utils/logger'

const forksLogger = logger.getSubLogger({ name: 'useForks' })

interface QueryVariables {
login: string
isFork?: boolean
}

const getForksInOrg = async (accessToken: string, login: string) => {
const queryVariables: QueryVariables = { login }
if (process.env.FORKS_ONLY === 'true') {
queryVariables.isFork = true
}
const res = await personalOctokit(accessToken)
.graphql.paginate<ForksObject>(getReposInOrgGQL, {
login,
isFork: true,
})
.graphql.paginate<ForksObject>(getReposInOrgGQL, queryVariables)
.catch((error: Error & { data: ForksObject }) => {
forksLogger.error('Error fetching forks', { error })
return error.data
Expand Down