Skip to content

Commit

Permalink
fix: issue config removed updated schema
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Sep 13, 2024
1 parent 2ea6146 commit a0da267
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 25 deletions.
4 changes: 0 additions & 4 deletions .github/.ubiquibot-config.yml

This file was deleted.

3 changes: 2 additions & 1 deletion src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
22 changes: 10 additions & 12 deletions src/adapters/supabase/helpers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export class Issues extends SuperSupabase {
super(supabase, context);
}

async createIssue(issueNodeId: string, payloadObject: Record<string, unknown> | null, isPrivate: boolean, plaintext: string | null, authorId: number) {
async createIssue(issueNodeId: string, payload: Record<string, unknown> | 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);
Expand All @@ -30,38 +31,35 @@ 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;
}
}
this.context.logger.info("Issue created successfully");
}

async updateIssue(plaintext: string | null, issueNodeId: string, payloadObject: Record<string, unknown> | null, isPrivate: boolean) {
async updateIssue(plaintext: string | null, issueNodeId: string, payload: Record<string, unknown> | 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<string, unknown> | null;
payload = null as Record<string, unknown> | 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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/handlers/add-issue.ts
Original file line number Diff line number Diff line change
@@ -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 });
Expand Down
2 changes: 1 addition & 1 deletion src/handlers/update-issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,5 @@ export async function plugin(inputs: PluginInputs, env: Env) {
adapters: {} as ReturnType<typeof createAdapters>,
};
context.adapters = createAdapters(supabase, voyageClient, context);
if (isIssueEvent(context)) {
return await runPlugin(context);
}
return await runPlugin(context);
}
1 change: 1 addition & 0 deletions supabase/migrations/20240912225853_issue_comments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a0da267

Please sign in to comment.