Skip to content

Commit

Permalink
chore: fix all eslint offending rules
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhenry committed Jun 11, 2024
1 parent 88f22e5 commit 2569f79
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 61 deletions.
21 changes: 11 additions & 10 deletions src/app/[organizationId]/forks/[forkId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
'use client'

import { useParams } from 'next/navigation'
Expand All @@ -21,23 +22,23 @@ import {
import Blankslate from '@primer/react/lib-esm/Blankslate/Blankslate'
import { DataTable, Table } from '@primer/react/lib-esm/DataTable'
import { Stack } from '@primer/react/lib-esm/Stack'
import { AppNotInstalledFlash } from 'app/components/flash/AppNotInstalledFlash'
import { SearchWithCreate } from 'app/components/search/SearchWithCreate'
import { useForkData } from 'hooks/useFork'
import { useOrgData } from 'hooks/useOrganization'
import { useCallback, useState } from 'react'
import { ForkBreadcrumbs } from 'app/components/breadcrumbs/ForkBreadcrumbs'
import { DeleteMirrorDialog } from 'app/components/dialog/DeleteMirrorDialog'
import { CreateMirrorDialog } from 'app/components/dialog/CreateMirrorDialog'
import { DeleteMirrorDialog } from 'app/components/dialog/DeleteMirrorDialog'
import { EditMirrorDialog } from 'app/components/dialog/EditMirrorDialog'
import { AppNotInstalledFlash } from 'app/components/flash/AppNotInstalledFlash'
import { ErrorFlash } from 'app/components/flash/ErrorFlash'
import { SuccessFlash } from 'app/components/flash/SuccessFlash'
import { ForkHeader } from 'app/components/header/ForkHeader'
import { Loading } from 'app/components/loading/Loading'
import { ErrorFlash } from 'app/components/flash/ErrorFlash'
import { EditMirrorDialog } from 'app/components/dialog/EditMirrorDialog'
import { SearchWithCreate } from 'app/components/search/SearchWithCreate'
import Fuse from 'fuse.js'
import { ForkHeader } from 'app/components/header/ForkHeader'
import { useForkData } from 'hooks/useFork'
import { useOrgData } from 'hooks/useOrganization'
import { useCallback, useState } from 'react'

const Fork = () => {
const { organizationId, forkId } = useParams()
const { organizationId } = useParams()
const { data, isLoading } = trpc.checkInstallation.useQuery({
orgId: organizationId as string,
})
Expand Down
6 changes: 5 additions & 1 deletion src/app/api/auth/[...nextauth]/route.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import NextAuth from 'next-auth'
import { NextRequest, NextResponse } from 'next/server'
import { nextAuthOptions } from '../lib/nextauth-options'

const handler = NextAuth(nextAuthOptions)
const handler = NextAuth(nextAuthOptions) as (
req: NextRequest,
res: NextResponse,
) => Promise<void>

export { handler as GET, handler as POST }
33 changes: 16 additions & 17 deletions src/app/api/auth/lib/nextauth-options.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { personalOctokit } from 'bot/octokit'
import { AuthOptions, Profile } from 'next-auth'
import { JWT } from 'next-auth/jwt'
import GitHub from 'next-auth/providers/github'
import { logger } from '../../../../utils/logger'
import { JWT } from 'next-auth/jwt'

import 'utils/proxy'

Expand Down Expand Up @@ -50,14 +50,15 @@ export const refreshAccessToken = async (
try {
authLogger.debug('Refreshing access token', { clientId })

const params = new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
grant_type: 'refresh_token',
})

const url =
'https://github.com/login/oauth/access_token?' +
new URLSearchParams({
client_id: clientId,
client_secret: clientSecret,
refresh_token: refreshToken,
grant_type: 'refresh_token',
})
'https://github.com/login/oauth/access_token?' + params.toString()

const response = await fetch(url, {
headers: {
Expand Down Expand Up @@ -130,7 +131,7 @@ export const nextAuthOptions: AuthOptions = {
},
},
callbacks: {
signIn: async (params) => {
signIn: (params) => {
authLogger.debug('Sign in callback')

const profile = params.profile as Profile & { login?: string }
Expand Down Expand Up @@ -161,15 +162,13 @@ export const nextAuthOptions: AuthOptions = {

return false
},
session: async ({ session, token }) => {
session: ({ session, token }) => {
if (token) {
session.user.name = token.name as string
session.user.image = token.image as string
session.user.email = token.email as string
session.user.accessToken = token.accessToken as string
session.expires = new Date(
token.accessTokenExpires as number,
).toISOString()
session.user.accessToken = token.accessToken
session.expires = new Date(token.accessTokenExpires).toISOString()
session.error = token.error
}

Expand All @@ -196,15 +195,15 @@ export const nextAuthOptions: AuthOptions = {
}

// Return previous token if the access token has not expired yet
if (Date.now() < (token.accessTokenExpires as number)) {
if (Date.now() < token.accessTokenExpires) {
authLogger.debug('Access token valid')
return token
}

authLogger.debug('Access token has expired')

// Return previous token if the refresh token has expired
if (Date.now() >= (token.refreshTokenExpires as number)) {
if (Date.now() >= token.refreshTokenExpires) {
authLogger.warn('Refresh token has expired')
return token
}
Expand All @@ -214,7 +213,7 @@ export const nextAuthOptions: AuthOptions = {
token,
process.env.GITHUB_CLIENT_ID!,
process.env.GITHUB_CLIENT_SECRET!,
token.refreshToken as string,
token.refreshToken,
)

// Return the previous token if we failed to refresh the token
Expand Down
4 changes: 2 additions & 2 deletions src/app/api/trpc/trpc-router.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import gitRouter from '../../../server/git/router'
import octokitRouter from '../../../server/octokit/router'
import reposRouter from '../../../server/repos/router'
import { t, procedure } from '../../../utils/trpc-server'
import { procedure, t } from '../../../utils/trpc-server'

export const healthCheckerRouter = t.router({
healthChecker: procedure.query(({}) => {
healthChecker: procedure.query(() => {
return 'ok'
}),
})
Expand Down
1 change: 0 additions & 1 deletion src/app/components/flash/AppNotInstalledFlash.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AlertIcon } from '@primer/octicons-react'
import { Box, Flash, Link, Octicon } from '@primer/react'
import { OrgData } from 'hooks/useOrganization'

interface AppNotInstalledFlashProps {
orgLogin: string
Expand Down
1 change: 1 addition & 0 deletions src/app/components/header/MainHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
'use client'

import { MarkGithubIcon } from '@primer/octicons-react'
Expand Down
4 changes: 2 additions & 2 deletions src/app/components/header/WelcomeHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BugIcon, GitBranchIcon, RepoForkedIcon } from '@primer/octicons-react'
import { Avatar, Octicon, Pagehead, Text } from '@primer/react'
import { RepoForkedIcon } from '@primer/octicons-react'
import { Octicon, Pagehead, Text } from '@primer/react'
import { Stack } from '@primer/react/lib-esm/Stack'

export const WelcomeHeader = () => {
Expand Down
1 change: 1 addition & 0 deletions src/app/context/AuthProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
'use client'

import { Session } from 'next-auth'
Expand Down
4 changes: 2 additions & 2 deletions src/bot/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export const getEnvConfig = () => {
)

const config = {
publicOrg: process.env.PUBLIC_ORG as string,
privateOrg: process.env.PUBLIC_ORG as string,
publicOrg: process.env.PUBLIC_ORG,
privateOrg: process.env.PUBLIC_ORG,
} as InternalContributionForksConfig

if (process.env.PRIVATE_ORG) {
Expand Down
20 changes: 11 additions & 9 deletions src/bot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ type CustomProperties = Record<string, string>
const botLogger = logger.getSubLogger({ name: 'bot' })

// Helper function to get the fork name from the repository custom properties
export const getForkName = async (props: CustomProperties) => {
export const getForkName = (props: CustomProperties) => {
return props.fork ?? null
}

// Helper function to get the metadata from the repository description
export const getMetadata = (description: string | null) => {
export const getMetadata = (
description: string | null,
): Record<string, string> => {
botLogger.debug('Getting metadata from repository description', {
description,
})
Expand All @@ -24,7 +26,7 @@ export const getMetadata = (description: string | null) => {
}

try {
return JSON.parse(description)
return JSON.parse(description) as Record<string, string>
} catch (error) {
botLogger.warn('Failed to parse repository description', { description })
return {}
Expand All @@ -33,12 +35,12 @@ export const getMetadata = (description: string | null) => {

function bot(app: Probot) {
// Catch-all to log all webhook events
app.onAny(async (context) => {
app.onAny((context) => {
botLogger.debug('Received webhook event `onAny`', { event: context.name })
})

// Good for debugging :)
app.on('ping', async (_) => {
app.on('ping', () => {
botLogger.debug('pong')
})

Expand All @@ -62,7 +64,7 @@ function bot(app: Probot) {
}

// Check repo properties to see if this is a mirror
const forkNameWithOwner = await getForkName(
const forkNameWithOwner = getForkName(
(
context.payload.repository as typeof context.payload.repository & {
custom_properties: CustomProperties
Expand Down Expand Up @@ -118,7 +120,7 @@ function bot(app: Probot) {
}

// Check repo properties to see if this is a mirror
const forkNameWithOwner = await getForkName(
const forkNameWithOwner = getForkName(
(
context.payload.repository as typeof context.payload.repository & {
custom_properties: CustomProperties
Expand Down Expand Up @@ -160,7 +162,7 @@ function bot(app: Probot) {
botLogger.info('Push event')

// Check repo properties to see if this is a mirror
const forkNameWithOwner = await getForkName(
const forkNameWithOwner = getForkName(
(
context.payload.repository as typeof context.payload.repository & {
custom_properties: CustomProperties
Expand Down Expand Up @@ -224,7 +226,7 @@ function bot(app: Probot) {
mirrorOwner,
orgId,
})
.catch((error) => {
.catch((error: Error) => {
botLogger.error('Failed to sync repository', { error })
})

Expand Down
2 changes: 1 addition & 1 deletion src/bot/octokit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const appOctokitLogger = logger.getSubLogger({ name: 'app-octokit' })

// This is a bug with the way the private key is stored in the docker env
// See https://github.com/moby/moby/issues/46773
let privateKey = process.env.PRIVATE_KEY?.includes('\\n')
const privateKey = process.env.PRIVATE_KEY?.includes('\\n')
? process.env.PRIVATE_KEY.replace(/\\n/g, '\n')
: process.env.PRIVATE_KEY!

Expand Down
10 changes: 3 additions & 7 deletions src/hooks/useFork.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { personalOctokit } from 'bot/octokit'
import { useSession } from 'next-auth/react'
import { useParams } from 'next/navigation'
import { Octokit } from 'octokit'
import { useEffect, useState } from 'react'

const getForkById = async (
accessToken: string,
repoId: string,
): Promise<
Awaited<ReturnType<Octokit['rest']['repos']['get']>>['data'] | null
> => {
const getForkById = async (accessToken: string, repoId: string) => {
try {
return (
await personalOctokit(accessToken).request('GET /repositories/:id', {
id: repoId,
})
).data
).data as Awaited<ReturnType<Octokit['rest']['repos']['get']>>['data']
} catch (error) {
console.error('Error fetching fork', { error })
return null
Expand Down
9 changes: 5 additions & 4 deletions src/hooks/useForks.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { getReposInOrgGQL } from 'bot/graphql'
import { personalOctokit } from 'bot/octokit'
import { useSession } from 'next-auth/react'
Expand All @@ -13,9 +14,9 @@ const getForksInOrg = async (accessToken: string, login: string) => {
login,
isFork: true,
})
.catch((err) => {
forksLogger.error('Error fetching forks', { err })
return err.data as ForksObject
.catch((error: Error & { data: ForksObject }) => {
forksLogger.error('Error fetching forks', { error })
return error.data
})

// the primer datatable component requires the data to not contain null
Expand Down Expand Up @@ -43,7 +44,7 @@ const getForksInOrg = async (accessToken: string, login: string) => {
languages: {
nodes: node.languages.nodes.map((node) => ({
name: node.name,
color: node.color as string,
color: node.color,
})),
},
refs: {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useOrganization.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-floating-promises */
import { personalOctokit } from 'bot/octokit'
import { useSession } from 'next-auth/react'
import { useParams, useRouter } from 'next/navigation'
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useOrganizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const useOrgsData = () => {
.then((orgs) => {
setOrganizationData(orgs.data)
})
.catch((error) => {
.catch((error: Error) => {
setError(error)
})
.finally(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/api/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ export const config = {
export default createNodeMiddleware(app, {
probot: createProbot({
defaults: {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
log: {
child: () => probotLogger,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
},
}),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const checkGitHubAppInstallationAuth = async (
owner: mirrorOrgOwner,
repo: mirrorRepo,
})
.catch((error) => {
.catch((error: Error) => {
middlewareLogger.error('Error checking github app installation auth', {
error,
})
Expand Down
15 changes: 12 additions & 3 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { Logger } from 'tslog'

// If you need logs during tests you can set the env var TEST_LOGGING=true
Expand All @@ -20,14 +21,22 @@ export const logger = new Logger({
/(?<=:\/\/)([^:]+):([^@]+)(?=@)/g,
],
overwrite: {
transportJSON: (logObjWithMeta: any) => {
transportJSON: (log) => {
let logObjWithMeta = log as {
_meta?: Record<string, any>
meta?: Record<string, any>
message?: string
data?: Record<string, any>
[key: string]: any
}

const meta = logObjWithMeta._meta

delete logObjWithMeta._meta

// If the log is only a string, then set "message"
if (
logObjWithMeta.hasOwnProperty('0') &&
Object.prototype.hasOwnProperty.call(logObjWithMeta, '0') &&
typeof logObjWithMeta['0'] === 'string'
) {
const message = logObjWithMeta['0']
Expand All @@ -44,7 +53,7 @@ export const logger = new Logger({
}
}

if (Object.keys(logObjWithMeta.data).length === 0) {
if (Object.keys(logObjWithMeta.data ?? {}).length === 0) {
delete logObjWithMeta.data
}

Expand Down

0 comments on commit 2569f79

Please sign in to comment.