From 702a9decdf9a0b2a449a37dcdf423bbe0f980185 Mon Sep 17 00:00:00 2001 From: Piero Bassa Date: Wed, 29 May 2024 12:30:57 +0200 Subject: [PATCH 1/3] chore: lint fix --- .eslintrc.js | 5 --- apps/backend/package.json | 3 +- apps/backend/src/dtos/submission.dto.ts | 1 - apps/backend/src/server.ts | 2 +- apps/backend/src/services/helpers/openai.ts | 36 +++++++-------------- apps/backend/src/utils/const/index.ts | 4 +-- apps/backend/src/utils/initializeOpenAI.ts | 2 +- 7 files changed, 17 insertions(+), 36 deletions(-) delete mode 100644 .eslintrc.js diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 02f791d..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,5 +0,0 @@ -/** @type {import("eslint").Linter.Config} */ -module.exports = { - root: true, - extends: ["@repo/eslint-config/index.js"], -}; diff --git a/apps/backend/package.json b/apps/backend/package.json index 8c2f48a..3aa3d3b 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -8,7 +8,6 @@ "dev:prod": "cross-env NODE_ENV=production nodemon", "build": "swc src -d dist --source-maps --copy-files", "build:tsc": "tsc && tsc-alias", - "test": "jest --forceExit --detectOpenHandles", "lint": "eslint --ignore-path .gitignore --ext .ts src", "lint:fix": "npm run lint -- --fix", "deploy:prod": "npm run build && pm2 start ecosystem.config.js --only prod", @@ -83,4 +82,4 @@ "tsconfig-paths": "^4.0.0", "typescript": "^4.7.4" } -} +} \ No newline at end of file diff --git a/apps/backend/src/dtos/submission.dto.ts b/apps/backend/src/dtos/submission.dto.ts index 8b0eb4d..803d3f5 100644 --- a/apps/backend/src/dtos/submission.dto.ts +++ b/apps/backend/src/dtos/submission.dto.ts @@ -18,4 +18,3 @@ export class SubmitDto { @IsNotEmpty() public captcha: string; } - \ No newline at end of file diff --git a/apps/backend/src/server.ts b/apps/backend/src/server.ts index 1615c2d..782d2a1 100644 --- a/apps/backend/src/server.ts +++ b/apps/backend/src/server.ts @@ -1,7 +1,7 @@ import { App } from '@/app'; import { ValidateEnv } from '@utils/validateEnv'; import { initializeOpenAI } from './utils/initializeOpenAI'; -import { SubmissionRoute } from './routes/submission.route'; +import { SubmissionRoute } from './routes/submission.route'; ValidateEnv(); diff --git a/apps/backend/src/services/helpers/openai.ts b/apps/backend/src/services/helpers/openai.ts index 0009b38..dbef22c 100644 --- a/apps/backend/src/services/helpers/openai.ts +++ b/apps/backend/src/services/helpers/openai.ts @@ -1,6 +1,6 @@ -import { OPENAI_API_KEY } from "@/config"; -import OpenAI from "openai"; -import { ChatCompletion } from "openai/resources"; +import { OPENAI_API_KEY } from '@/config'; +import OpenAI from 'openai'; +import { ChatCompletion } from 'openai/resources'; export class OpenAIHelper { private openai: OpenAI; @@ -19,28 +19,20 @@ export class OpenAIHelper { dangerouslyAllowBrowser: true, // TODO: Check if this is necessary }); - public askChatGPTAboutImage = async ({ - base64Image, - maxTokens = 350, - prompt, - }: { - base64Image: string; - prompt: string; - maxTokens?: number; - }) => + public askChatGPTAboutImage = async ({ base64Image, maxTokens = 350, prompt }: { base64Image: string; prompt: string; maxTokens?: number }) => this.openai.chat.completions.create({ - model: "gpt-4-vision-preview", + model: 'gpt-4-vision-preview', max_tokens: maxTokens, messages: [ { - role: "user", + role: 'user', content: [ { - type: "text", + type: 'text', text: prompt, }, { - type: "image_url", + type: 'image_url', image_url: { url: base64Image, }, @@ -50,15 +42,11 @@ export class OpenAIHelper { ], }); - public getResponseJSONString = (response: ChatCompletion) => - response.choices[0].message.content; + public getResponseJSONString = (response: ChatCompletion) => response.choices[0].message.content; - private cleanChatGPTJSONString = (jsonString: string) => - jsonString.replace("```json", "").replace("```", ""); + private cleanChatGPTJSONString = (jsonString: string) => jsonString.replace('```json', '').replace('```', ''); - public parseChatGPTJSONString = ( - jsonString?: string | null - ): Response | undefined => { + public parseChatGPTJSONString = (jsonString?: string | null): Response | undefined => { if (!jsonString) { return; } @@ -68,7 +56,7 @@ export class OpenAIHelper { const parsed = JSON.parse(content); return parsed; } catch (e) { - console.error("Failing parsing Chat GPT response:", e); + console.error('Failing parsing Chat GPT response:', e); } } }; diff --git a/apps/backend/src/utils/const/index.ts b/apps/backend/src/utils/const/index.ts index 10ff5d4..050e5f3 100644 --- a/apps/backend/src/utils/const/index.ts +++ b/apps/backend/src/utils/const/index.ts @@ -1,2 +1,2 @@ -export * from "./abi"; -export * from "./network"; \ No newline at end of file +export * from './abi'; +export * from './network'; diff --git a/apps/backend/src/utils/initializeOpenAI.ts b/apps/backend/src/utils/initializeOpenAI.ts index 5b97f98..bb0e1c4 100644 --- a/apps/backend/src/utils/initializeOpenAI.ts +++ b/apps/backend/src/utils/initializeOpenAI.ts @@ -1,4 +1,4 @@ -import { OpenAIHelper } from "@/services/helpers"; +import { OpenAIHelper } from '@/services/helpers'; export const initializeOpenAI = () => { return new OpenAIHelper(); From 27782dc5d39ca35c49dd5ac2a702616b0a82160b Mon Sep 17 00:00:00 2001 From: Piero Bassa Date: Wed, 29 May 2024 12:33:11 +0200 Subject: [PATCH 2/3] feat: lint fix script --- apps/frontend/package.json | 1 + package.json | 1 + turbo.json | 1 + 3 files changed, 3 insertions(+) diff --git a/apps/frontend/package.json b/apps/frontend/package.json index 2490a3b..94643f1 100644 --- a/apps/frontend/package.json +++ b/apps/frontend/package.json @@ -7,6 +7,7 @@ "dev": "vite --port 8082 --host", "build": "tsc && vite build", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", + "lint:fix": "yarn lint --fix", "preview": "vite preview" }, "dependencies": { diff --git a/package.json b/package.json index d89d8cd..d533aa0 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "build": "turbo build", "dev": "turbo dev", "lint": "turbo lint", + "lint:fix": "turbo lint:fix", "test": "turbo test", "format": "prettier --write \"**/*.{ts,tsx,md}\"", "contracts:deploy:solo": "turbo run deploy:solo", diff --git a/turbo.json b/turbo.json index eb421ff..4b095d5 100644 --- a/turbo.json +++ b/turbo.json @@ -10,6 +10,7 @@ ] }, "lint": {}, + "lint:fix": {}, "dev": { "cache": false, "persistent": true From a9131b82f028436d4f55c54e76418f181a1da75e Mon Sep 17 00:00:00 2001 From: Piero Bassa Date: Wed, 29 May 2024 12:35:15 +0200 Subject: [PATCH 3/3] feat: build and test workflow --- .github/workflows/build-and-test.yml | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/build-and-test.yml diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 0000000..2612409 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,36 @@ +name: Unit Testing + +on: + workflow_dispatch: + pull_request: + branches: + - main + +jobs: + build-and-test: + name: Build and Test + runs-on: ubuntu-latest + strategy: + fail-fast: false + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Use Node v20 + uses: actions/setup-node@v3 + with: + node-version-file: .nvmrc + cache: "yarn" + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Build + run: yarn build + + - name: Lint + run: yarn lint + + - name: Unit Tests + run: yarn test \ No newline at end of file