From a0da267feb7690317a5ced93c5d2ef92708d3dfc Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Fri, 13 Sep 2024 00:38:30 -0400 Subject: [PATCH] fix: issue config removed updated schema --- .github/.ubiquibot-config.yml | 4 ---- src/adapters/supabase/helpers/comment.ts | 3 ++- src/adapters/supabase/helpers/issues.ts | 22 +++++++++---------- src/handlers/add-issue.ts | 8 +++---- src/handlers/update-issue.ts | 2 +- src/plugin.ts | 4 +--- .../20240912225853_issue_comments.sql | 1 + 7 files changed, 19 insertions(+), 25 deletions(-) delete mode 100644 .github/.ubiquibot-config.yml diff --git a/.github/.ubiquibot-config.yml b/.github/.ubiquibot-config.yml deleted file mode 100644 index b15d7dd..0000000 --- a/.github/.ubiquibot-config.yml +++ /dev/null @@ -1,4 +0,0 @@ - id: test-app - uses: - - plugin: https://ubiquity-os-comment-vector-embeddings.sshivaditya.workers.dev - runsOn: [ "issue_comment.created", "issue_comment.edited", "issue_comment.deleted"] \ No newline at end of file diff --git a/src/adapters/supabase/helpers/comment.ts b/src/adapters/supabase/helpers/comment.ts index 0f59531..e64402b 100644 --- a/src/adapters/supabase/helpers/comment.ts +++ b/src/adapters/supabase/helpers/comment.ts @@ -42,8 +42,9 @@ export class Comment extends SuperSupabase { } const { error } = await this.supabase .from("issue_comments") - .insert([{ id: commentNodeId, plaintext, author_id: authorId, type: "comment", payload, embedding: embedding, issueId }]); + .insert([{ id: commentNodeId, plaintext, author_id: authorId, type: "comment", payload, embedding: embedding, issue_id: issueId }]); if (error) { + console.log(error.message, error.details, { id: commentNodeId, plaintext, author_id: authorId, type: "comment", payload, embedding }); this.context.logger.error("Error creating comment", error); return; } diff --git a/src/adapters/supabase/helpers/issues.ts b/src/adapters/supabase/helpers/issues.ts index e7d7e95..0040796 100644 --- a/src/adapters/supabase/helpers/issues.ts +++ b/src/adapters/supabase/helpers/issues.ts @@ -17,8 +17,9 @@ export class Issues extends SuperSupabase { super(supabase, context); } - async createIssue(issueNodeId: string, payloadObject: Record | null, isPrivate: boolean, plaintext: string | null, authorId: number) { + async createIssue(issueNodeId: string, payload: Record | null, isPrivate: boolean, plaintext: string | null, authorId: number) { //First Check if the issue already exists + console.log(payload); const { data, error } = await this.supabase.from("issues").select("*").eq("id", issueNodeId); if (error) { this.context.logger.error("Error creating issue", error); @@ -30,13 +31,12 @@ export class Issues extends SuperSupabase { } else { const embedding = await this.context.adapters.voyage.embedding.createEmbedding(plaintext); if (isPrivate) { - payloadObject = null; + payload = null; plaintext = null; } - const { error } = await this.supabase - .from("issues") - .insert([{ id: issueNodeId, payloadObject, type: "issue", plaintext, author_id: authorId, embedding }]); + const { error } = await this.supabase.from("issues").insert([{ id: issueNodeId, payload, type: "issue", plaintext, author_id: authorId, embedding }]); if (error) { + console.log(error.message, error.details, { id: issueNodeId, payload, type: "issue", plaintext, author_id: authorId, embedding }); this.context.logger.error("Error creating issue", error); return; } @@ -44,24 +44,22 @@ export class Issues extends SuperSupabase { this.context.logger.info("Issue created successfully"); } - async updateIssue(plaintext: string | null, issueNodeId: string, payloadObject: Record | null, isPrivate: boolean) { + async updateIssue(plaintext: string | null, issueNodeId: string, payload: Record | null, isPrivate: boolean) { //Create the embedding for this comment const embedding = Array.from(await this.context.adapters.voyage.embedding.createEmbedding(plaintext)); if (isPrivate) { plaintext = null as string | null; - payloadObject = null as Record | null; + payload = null as Record | null; } - const { error } = await this.supabase - .from("issue_comments") - .update({ plaintext, embedding: embedding, payloadObject, modified_at: new Date() }) - .eq("id", issueNodeId); + console.log({ id: issueNodeId, plaintext, payload, embedding }); + const { error } = await this.supabase.from("issues").update({ plaintext, embedding: embedding, payload, modified_at: new Date() }).eq("id", issueNodeId); if (error) { this.context.logger.error("Error updating comment", error); } } async deleteIssue(issueNodeId: string) { - const { error } = await this.supabase.from("issue_comments").delete().eq("id", issueNodeId); + const { error } = await this.supabase.from("issues").delete().eq("id", issueNodeId); if (error) { this.context.logger.error("Error deleting comment", error); } diff --git a/src/handlers/add-issue.ts b/src/handlers/add-issue.ts index ce7c315..4264a44 100644 --- a/src/handlers/add-issue.ts +++ b/src/handlers/add-issue.ts @@ -1,19 +1,19 @@ import { Context } from "../types"; +import { IssuePayload } from "../types/payload"; export async function addIssue(context: Context) { const { logger, - payload, adapters: { supabase }, } = context; - const payloadObject = payload; - const plaintext = payload.issue.body + payload.issue.title || ""; + const { payload } = context as { payload: IssuePayload }; + const plaintext = payload.issue.body + " " + payload.issue.title || ""; const authorId = payload.issue.user?.id || -1; const nodeId = payload.issue.node_id; const isPrivate = payload.repository.private; try { - await supabase.issue.createIssue(nodeId, payloadObject, isPrivate, plaintext, authorId); + await supabase.issue.createIssue(nodeId, payload, isPrivate, plaintext, authorId); } catch (error) { if (error instanceof Error) { logger.error(`Error creating issue:`, { error: error, stack: error.stack }); diff --git a/src/handlers/update-issue.ts b/src/handlers/update-issue.ts index fad405c..64f3548 100644 --- a/src/handlers/update-issue.ts +++ b/src/handlers/update-issue.ts @@ -10,7 +10,7 @@ export async function updateIssue(context: Context) { const payloadObject = payload; const nodeId = payload.issue.node_id; const isPrivate = payload.repository.private; - const plaintext = payload.issue.body + payload.issue.title || ""; + const plaintext = payload.issue.body + " " + payload.issue.title || ""; // Fetch the previous issue and update it in the db try { await supabase.issue.updateIssue(plaintext, nodeId, payloadObject, isPrivate); diff --git a/src/plugin.ts b/src/plugin.ts index fa67919..2f7dad8 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -62,7 +62,5 @@ export async function plugin(inputs: PluginInputs, env: Env) { adapters: {} as ReturnType, }; context.adapters = createAdapters(supabase, voyageClient, context); - if (isIssueEvent(context)) { - return await runPlugin(context); - } + return await runPlugin(context); } diff --git a/supabase/migrations/20240912225853_issue_comments.sql b/supabase/migrations/20240912225853_issue_comments.sql index 3a8764a..a6e24b4 100644 --- a/supabase/migrations/20240912225853_issue_comments.sql +++ b/supabase/migrations/20240912225853_issue_comments.sql @@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS issues ( plaintext text, embedding Vector(1024) not null, payload jsonb, + author_id VARCHAR not null, type text not null default 'issue', created_at timestamptz not null default now(), modified_at timestamptz not null default now()