From 16786d76ee7a598c885f15af1baeadcf6a471b2c Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Wed, 28 Aug 2024 11:02:01 -0400 Subject: [PATCH] fix: github workflow, types package.json, env examples --- .dev.vars.example | 4 +- .env.example | 4 +- .github/workflows/database.yml | 67 ++++ database.types.ts | 79 ----- eslint.config.mjs | 2 +- package.json | 4 +- src/plugin.ts | 6 +- src/types/database.ts | 616 +++++++++++++++++++++++++++++++++ 8 files changed, 696 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/database.yml delete mode 100644 database.types.ts create mode 100644 src/types/database.ts diff --git a/.dev.vars.example b/.dev.vars.example index e49d79a..6ceaeff 100644 --- a/.dev.vars.example +++ b/.dev.vars.example @@ -1 +1,3 @@ -MY_SECRET="MY_SECRET" +SUPABASE_URL="" +SUPABASE_KEY="" +OPENAI_API_KEY="" \ No newline at end of file diff --git a/.env.example b/.env.example index e49d79a..0272714 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,3 @@ -MY_SECRET="MY_SECRET" +SUPABASE_URL= +SUPABASE_KEY= +OPENAI_API_KEY= \ No newline at end of file diff --git a/.github/workflows/database.yml b/.github/workflows/database.yml new file mode 100644 index 0000000..5511f5e --- /dev/null +++ b/.github/workflows/database.yml @@ -0,0 +1,67 @@ +name: Database + +on: + push: + branches: + - main + +env: + SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }} + SUPABASE_DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }} + SUPABASE_PROJECT_ID: ${{ secrets.SUPABASE_PROJECT_ID }} + +jobs: + run-migration: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.10.0" + + - uses: supabase/setup-cli@v1 + with: + version: latest + + - name: Link Supabase project + run: supabase link --project-ref $SUPABASE_PROJECT_ID + + - name: Run migrations + run: supabase db push + + generate_types: + runs-on: ubuntu-latest + needs: + - run-migration + permissions: + contents: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: "20.10.0" + + - name: Generate Supabase Types + run: | + yarn install + yarn run "supabase:generate:remote" + + - name: Commit and Push generated types + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + git add src/types/database.ts + if [ -n "$(git diff-index --cached --name-only HEAD)" ]; then + git commit -m "chore: updated generated Supabase types" || echo "Lint-staged check failed" + git push origin main + else + echo "No changes to commit" + fi + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/database.types.ts b/database.types.ts deleted file mode 100644 index e405a87..0000000 --- a/database.types.ts +++ /dev/null @@ -1,79 +0,0 @@ -/* eslint-disable */ - -export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[]; - -export type Database = { - public: { - Tables: { - issue_comments: { - Row: { - commentbody: string; - embedding: string; - id: number; - issuebody: string | null; - }; - Insert: { - commentbody: string; - embedding: string; - id: number; - issuebody?: string | null; - }; - Update: { - commentbody?: string; - embedding?: string; - id?: number; - issuebody?: string | null; - }; - Relationships: []; - }; - test: { - Row: { - created_at: string; - id: number; - }; - Insert: { - created_at?: string; - id?: number; - }; - Update: { - created_at?: string; - id?: number; - }; - Relationships: []; - }; - }; - Views: { - [_ in never]: never; - }; - Functions: { - [_ in never]: never; - }; - Enums: { - [_ in never]: never; - }; - CompositeTypes: { - [_ in never]: never; - }; - }; -}; - -type PublicSchema = Database[Extract]; - -export type Tables< - PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] & PublicSchema["Views"]) | { schema: keyof Database }, - TableName extends PublicTableNameOrOptions extends { schema: keyof Database } - ? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] & Database[PublicTableNameOrOptions["schema"]]["Views"]) - : never = never, -> = PublicTableNameOrOptions extends { schema: keyof Database } - ? (Database[PublicTableNameOrOptions["schema"]]["Tables"] & Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends { - Row: infer R; - } - ? R - : never - : PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] & PublicSchema["Views"]) - ? (PublicSchema["Tables"] & PublicSchema["Views"])[PublicTableNameOrOptions] extends { - Row: infer R; - } - ? R - : never - : never; diff --git a/eslint.config.mjs b/eslint.config.mjs index e53d263..f43237a 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,7 +9,7 @@ export default tsEslint.config({ "@typescript-eslint": tsEslint.plugin, "check-file": checkFile, }, - ignores: [".github/knip.ts"], + ignores: [".github/knip.ts", "src/types/database.ts"], extends: [eslint.configs.recommended, ...tsEslint.configs.recommended, sonarjs.configs.recommended], languageOptions: { parser: tsEslint.parser, diff --git a/package.json b/package.json index 7abe0d6..286aa83 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,9 @@ "knip-ci": "", "prepare": "husky install", "test": "jest --setupFiles dotenv/config --coverage", - "worker": "wrangler dev --env dev --port 5000" + "worker": "wrangler dev --env dev --port 4000", + "supabase:generate:local": "supabase gen types typescript --local > src/types/database.ts", + "supabase:generate:remote": "cross-env-shell \"supabase gen types typescript --project-id $SUPABASE_PROJECT_ID --schema public > src/types/database.ts\"" }, "keywords": [ "typescript", diff --git a/src/plugin.ts b/src/plugin.ts index 5f24069..4197ff6 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -3,7 +3,7 @@ import { Env, PluginInputs } from "./types"; import { Context } from "./types"; import { isIssueCommentEvent } from "./types/typeguards"; import { LogLevel, Logs } from "@ubiquity-dao/ubiquibot-logger"; -import { Database } from "./../database.types"; +import { Database } from "./types/database"; import { createAdapters } from "./adapters"; import { createClient } from "@supabase/supabase-js"; import { addComments } from "./handlers/add-comments"; @@ -24,9 +24,9 @@ export async function runPlugin(context: Context) { return await deleteComment(context); case "issue_comment.edited": return await updateComment(context); - default: - logger.error(`Unsupported event: ${eventName}`); } + } else { + logger.error(`Unsupported event: ${eventName}`); } logger.ok(`Exiting plugin`); } diff --git a/src/types/database.ts b/src/types/database.ts new file mode 100644 index 0000000..5e38913 --- /dev/null +++ b/src/types/database.ts @@ -0,0 +1,616 @@ +export type Json = string | number | boolean | null | { [key: string]: Json | undefined } | Json[]; + +export type Database = { + graphql_public: { + Tables: { + [_ in never]: never; + }; + Views: { + [_ in never]: never; + }; + Functions: { + graphql: { + Args: { + operationName?: string; + query?: string; + variables?: Json; + extensions?: Json; + }; + Returns: Json; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; + }; + public: { + Tables: { + issue_comments: { + Row: { + commentbody: string; + embedding: string; + id: number; + issuebody: string | null; + }; + Insert: { + commentbody: string; + embedding: string; + id: number; + issuebody?: string | null; + }; + Update: { + commentbody?: string; + embedding?: string; + id?: number; + issuebody?: string | null; + }; + Relationships: []; + }; + }; + Views: { + [_ in never]: never; + }; + Functions: { + binary_quantize: + | { + Args: { + "": string; + }; + Returns: unknown; + } + | { + Args: { + "": unknown; + }; + Returns: unknown; + }; + halfvec_avg: { + Args: { + "": number[]; + }; + Returns: unknown; + }; + halfvec_out: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + halfvec_send: { + Args: { + "": unknown; + }; + Returns: string; + }; + halfvec_typmod_in: { + Args: { + "": unknown[]; + }; + Returns: number; + }; + hnsw_bit_support: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + hnsw_halfvec_support: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + hnsw_sparsevec_support: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + hnswhandler: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + ivfflat_bit_support: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + ivfflat_halfvec_support: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + ivfflathandler: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + l2_norm: + | { + Args: { + "": unknown; + }; + Returns: number; + } + | { + Args: { + "": unknown; + }; + Returns: number; + }; + l2_normalize: + | { + Args: { + "": string; + }; + Returns: string; + } + | { + Args: { + "": unknown; + }; + Returns: unknown; + } + | { + Args: { + "": unknown; + }; + Returns: unknown; + }; + sparsevec_out: { + Args: { + "": unknown; + }; + Returns: unknown; + }; + sparsevec_send: { + Args: { + "": unknown; + }; + Returns: string; + }; + sparsevec_typmod_in: { + Args: { + "": unknown[]; + }; + Returns: number; + }; + vector_avg: { + Args: { + "": number[]; + }; + Returns: string; + }; + vector_dims: + | { + Args: { + "": string; + }; + Returns: number; + } + | { + Args: { + "": unknown; + }; + Returns: number; + }; + vector_norm: { + Args: { + "": string; + }; + Returns: number; + }; + vector_out: { + Args: { + "": string; + }; + Returns: unknown; + }; + vector_send: { + Args: { + "": string; + }; + Returns: string; + }; + vector_typmod_in: { + Args: { + "": unknown[]; + }; + Returns: number; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; + }; + storage: { + Tables: { + buckets: { + Row: { + allowed_mime_types: string[] | null; + avif_autodetection: boolean | null; + created_at: string | null; + file_size_limit: number | null; + id: string; + name: string; + owner: string | null; + owner_id: string | null; + public: boolean | null; + updated_at: string | null; + }; + Insert: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id: string; + name: string; + owner?: string | null; + owner_id?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Update: { + allowed_mime_types?: string[] | null; + avif_autodetection?: boolean | null; + created_at?: string | null; + file_size_limit?: number | null; + id?: string; + name?: string; + owner?: string | null; + owner_id?: string | null; + public?: boolean | null; + updated_at?: string | null; + }; + Relationships: []; + }; + migrations: { + Row: { + executed_at: string | null; + hash: string; + id: number; + name: string; + }; + Insert: { + executed_at?: string | null; + hash: string; + id: number; + name: string; + }; + Update: { + executed_at?: string | null; + hash?: string; + id?: number; + name?: string; + }; + Relationships: []; + }; + objects: { + Row: { + bucket_id: string | null; + created_at: string | null; + id: string; + last_accessed_at: string | null; + metadata: Json | null; + name: string | null; + owner: string | null; + owner_id: string | null; + path_tokens: string[] | null; + updated_at: string | null; + user_metadata: Json | null; + version: string | null; + }; + Insert: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + owner_id?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + user_metadata?: Json | null; + version?: string | null; + }; + Update: { + bucket_id?: string | null; + created_at?: string | null; + id?: string; + last_accessed_at?: string | null; + metadata?: Json | null; + name?: string | null; + owner?: string | null; + owner_id?: string | null; + path_tokens?: string[] | null; + updated_at?: string | null; + user_metadata?: Json | null; + version?: string | null; + }; + Relationships: [ + { + foreignKeyName: "objects_bucketId_fkey"; + columns: ["bucket_id"]; + isOneToOne: false; + referencedRelation: "buckets"; + referencedColumns: ["id"]; + }, + ]; + }; + s3_multipart_uploads: { + Row: { + bucket_id: string; + created_at: string; + id: string; + in_progress_size: number; + key: string; + owner_id: string | null; + upload_signature: string; + user_metadata: Json | null; + version: string; + }; + Insert: { + bucket_id: string; + created_at?: string; + id: string; + in_progress_size?: number; + key: string; + owner_id?: string | null; + upload_signature: string; + user_metadata?: Json | null; + version: string; + }; + Update: { + bucket_id?: string; + created_at?: string; + id?: string; + in_progress_size?: number; + key?: string; + owner_id?: string | null; + upload_signature?: string; + user_metadata?: Json | null; + version?: string; + }; + Relationships: [ + { + foreignKeyName: "s3_multipart_uploads_bucket_id_fkey"; + columns: ["bucket_id"]; + isOneToOne: false; + referencedRelation: "buckets"; + referencedColumns: ["id"]; + }, + ]; + }; + s3_multipart_uploads_parts: { + Row: { + bucket_id: string; + created_at: string; + etag: string; + id: string; + key: string; + owner_id: string | null; + part_number: number; + size: number; + upload_id: string; + version: string; + }; + Insert: { + bucket_id: string; + created_at?: string; + etag: string; + id?: string; + key: string; + owner_id?: string | null; + part_number: number; + size?: number; + upload_id: string; + version: string; + }; + Update: { + bucket_id?: string; + created_at?: string; + etag?: string; + id?: string; + key?: string; + owner_id?: string | null; + part_number?: number; + size?: number; + upload_id?: string; + version?: string; + }; + Relationships: [ + { + foreignKeyName: "s3_multipart_uploads_parts_bucket_id_fkey"; + columns: ["bucket_id"]; + isOneToOne: false; + referencedRelation: "buckets"; + referencedColumns: ["id"]; + }, + { + foreignKeyName: "s3_multipart_uploads_parts_upload_id_fkey"; + columns: ["upload_id"]; + isOneToOne: false; + referencedRelation: "s3_multipart_uploads"; + referencedColumns: ["id"]; + }, + ]; + }; + }; + Views: { + [_ in never]: never; + }; + Functions: { + can_insert_object: { + Args: { + bucketid: string; + name: string; + owner: string; + metadata: Json; + }; + Returns: undefined; + }; + extension: { + Args: { + name: string; + }; + Returns: string; + }; + filename: { + Args: { + name: string; + }; + Returns: string; + }; + foldername: { + Args: { + name: string; + }; + Returns: unknown; + }; + get_size_by_bucket: { + Args: Record; + Returns: { + size: number; + bucket_id: string; + }[]; + }; + list_multipart_uploads_with_delimiter: { + Args: { + bucket_id: string; + prefix_param: string; + delimiter_param: string; + max_keys?: number; + next_key_token?: string; + next_upload_token?: string; + }; + Returns: { + key: string; + id: string; + created_at: string; + }[]; + }; + list_objects_with_delimiter: { + Args: { + bucket_id: string; + prefix_param: string; + delimiter_param: string; + max_keys?: number; + start_after?: string; + next_token?: string; + }; + Returns: { + name: string; + id: string; + metadata: Json; + updated_at: string; + }[]; + }; + operation: { + Args: Record; + Returns: string; + }; + search: { + Args: { + prefix: string; + bucketname: string; + limits?: number; + levels?: number; + offsets?: number; + search?: string; + sortcolumn?: string; + sortorder?: string; + }; + Returns: { + name: string; + id: string; + updated_at: string; + created_at: string; + last_accessed_at: string; + metadata: Json; + }[]; + }; + }; + Enums: { + [_ in never]: never; + }; + CompositeTypes: { + [_ in never]: never; + }; + }; +}; + +type PublicSchema = Database[Extract]; + +export type Tables< + PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] & PublicSchema["Views"]) | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } + ? keyof (Database[PublicTableNameOrOptions["schema"]]["Tables"] & Database[PublicTableNameOrOptions["schema"]]["Views"]) + : never = never, +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? (Database[PublicTableNameOrOptions["schema"]]["Tables"] & Database[PublicTableNameOrOptions["schema"]]["Views"])[TableName] extends { + Row: infer R; + } + ? R + : never + : PublicTableNameOrOptions extends keyof (PublicSchema["Tables"] & PublicSchema["Views"]) + ? (PublicSchema["Tables"] & PublicSchema["Views"])[PublicTableNameOrOptions] extends { + Row: infer R; + } + ? R + : never + : never; + +export type TablesInsert< + PublicTableNameOrOptions extends keyof PublicSchema["Tables"] | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] : never = never, +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { + Insert: infer I; + } + ? I + : never + : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] + ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { + Insert: infer I; + } + ? I + : never + : never; + +export type TablesUpdate< + PublicTableNameOrOptions extends keyof PublicSchema["Tables"] | { schema: keyof Database }, + TableName extends PublicTableNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicTableNameOrOptions["schema"]]["Tables"] : never = never, +> = PublicTableNameOrOptions extends { schema: keyof Database } + ? Database[PublicTableNameOrOptions["schema"]]["Tables"][TableName] extends { + Update: infer U; + } + ? U + : never + : PublicTableNameOrOptions extends keyof PublicSchema["Tables"] + ? PublicSchema["Tables"][PublicTableNameOrOptions] extends { + Update: infer U; + } + ? U + : never + : never; + +export type Enums< + PublicEnumNameOrOptions extends keyof PublicSchema["Enums"] | { schema: keyof Database }, + EnumName extends PublicEnumNameOrOptions extends { schema: keyof Database } ? keyof Database[PublicEnumNameOrOptions["schema"]]["Enums"] : never = never, +> = PublicEnumNameOrOptions extends { schema: keyof Database } + ? Database[PublicEnumNameOrOptions["schema"]]["Enums"][EnumName] + : PublicEnumNameOrOptions extends keyof PublicSchema["Enums"] + ? PublicSchema["Enums"][PublicEnumNameOrOptions] + : never;