generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: issue_comments linting added issue_comments:edited, created and …
…deleted
- Loading branch information
1 parent
e50de1d
commit 9c0de23
Showing
20 changed files
with
498 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { SupabaseClient } from "@supabase/supabase-js"; | ||
import { Context } from "../types"; | ||
import { Comment } from "./supabase/helpers/comment"; | ||
import { SuperSupabase } from "./supabase/helpers/supabase"; | ||
import { SuperOpenAi } from "./openai/helpers/openai"; | ||
import OpenAI from "openai"; | ||
import { Embedding } from "./openai/helpers/embedding"; | ||
|
||
export function createAdapters(supabaseClient: SupabaseClient, openai: OpenAI, context: Context) { | ||
return { | ||
supabase: { | ||
comment: new Comment(supabaseClient, context), | ||
super: new SuperSupabase(supabaseClient, context), | ||
}, | ||
openai: { | ||
embedding: new Embedding(openai, context), | ||
super: new SuperOpenAi(openai, context), | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import OpenAI from "openai"; | ||
import { Context } from "../../../types"; | ||
import { SuperOpenAi } from "./openai"; | ||
const VECTOR_SIZE = 512; | ||
|
||
export class Embedding extends SuperOpenAi { | ||
protected context: Context; | ||
|
||
constructor(client: OpenAI, context: Context) { | ||
super(client, context); | ||
this.context = context; | ||
} | ||
|
||
async createEmbedding(text: string): Promise<number[]> { | ||
const params: OpenAI.EmbeddingCreateParams = { | ||
model: "text-embedding-3-small", | ||
input: text, | ||
dimensions: VECTOR_SIZE, | ||
}; | ||
const response = await this.client.embeddings.create({ | ||
...params, | ||
}); | ||
return response.data[0]?.embedding; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { OpenAI } from "openai"; | ||
import { Context } from "../../../types/context"; | ||
|
||
export class SuperOpenAi { | ||
protected client: OpenAI; | ||
protected context: Context; | ||
|
||
constructor(client: OpenAI, context: Context) { | ||
this.client = client; | ||
this.context = context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { SupabaseClient } from "@supabase/supabase-js"; | ||
import { SuperSupabase } from "./supabase"; | ||
import { Context } from "../../../types/context"; | ||
|
||
export class Comment extends SuperSupabase { | ||
constructor(supabase: SupabaseClient, context: Context) { | ||
super(supabase, context); | ||
} | ||
|
||
async createComment(commentBody: string, commentId: number) { | ||
//First Check if the comment already exists | ||
const { data, error } = await this.supabase.from("issue_comments").select("*").eq("id", commentId); | ||
if (error) { | ||
this.context.logger.error("Error creating comment", error); | ||
return; | ||
} | ||
if (data && data.length > 0) { | ||
this.context.logger.info("Comment already exists"); | ||
return; | ||
} else { | ||
//Create the embedding for this comment | ||
const embedding = await this.context.adapters.openai.embedding.createEmbedding(commentBody); | ||
const { error } = await this.supabase.from("issue_comments").insert([{ id: commentId, body: commentBody, embedding: embedding }]); | ||
if (error) { | ||
this.context.logger.error("Error creating comment", error); | ||
return; | ||
} | ||
} | ||
this.context.logger.info("Comment created successfully"); | ||
} | ||
|
||
async updateComment(commentBody: string, commentId: number) { | ||
//Create the embedding for this comment | ||
const embedding = Array.from(await this.context.adapters.openai.embedding.createEmbedding(commentBody)); | ||
const { error } = await this.supabase.from("issue_comments").update({ body: commentBody, embedding: embedding }).eq("id", commentId); | ||
if (error) { | ||
this.context.logger.error("Error updating comment", error); | ||
} | ||
} | ||
|
||
async deleteComment(commentId: number) { | ||
const { error } = await this.supabase.from("issue_comments").delete().eq("id", commentId); | ||
if (error) { | ||
this.context.logger.error("Error deleting comment", error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { SupabaseClient } from "@supabase/supabase-js"; | ||
import { Context } from "../../../types/context"; | ||
|
||
export class SuperSupabase { | ||
protected supabase: SupabaseClient; | ||
protected context: Context; | ||
|
||
constructor(supabase: SupabaseClient, context: Context) { | ||
this.supabase = supabase; | ||
this.context = context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Context } from "../types"; | ||
|
||
export async function addComments(context: Context) { | ||
const { | ||
logger, | ||
payload, | ||
adapters: { supabase }, | ||
} = context; | ||
|
||
const sender = payload.comment.user?.login; | ||
const repo = payload.repository.name; | ||
const issueNumber = payload.issue.number; | ||
const owner = payload.repository.owner.login; | ||
const body = payload.comment.body; | ||
|
||
// Log the payload | ||
logger.info(`Executing addComments:`, { sender, repo, issueNumber, owner }); | ||
|
||
// Add the comment to the database | ||
try { | ||
await supabase.comment.createComment(body, payload.comment.id); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
logger.error(`Error creating comment:`, { error: error, stack: error.stack }); | ||
throw error; | ||
} else { | ||
logger.error(`Error creating comment:`, { err: error, error: new Error() }); | ||
throw error; | ||
} | ||
} | ||
|
||
logger.ok(`Successfully created comment!`); | ||
logger.verbose(`Exiting addComments`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Context } from "../types"; | ||
|
||
export async function deleteComment(context: Context) { | ||
const { | ||
logger, | ||
payload, | ||
adapters: { supabase }, | ||
} = context; | ||
|
||
const sender = payload.comment.user?.login; | ||
const repo = payload.repository.name; | ||
const issueNumber = payload.issue.number; | ||
const owner = payload.repository.owner.login; | ||
|
||
// Log the payload | ||
logger.debug(`Executing deleteComment:`, { sender, repo, issueNumber, owner }); | ||
|
||
// Add the comment to the database | ||
try { | ||
await supabase.comment.deleteComment(payload.comment.id); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
logger.error(`Error deleting comment:`, { error: error, stack: error.stack }); | ||
throw error; | ||
} else { | ||
logger.error(`Error deleting comment:`, { err: error, error: new Error() }); | ||
throw error; | ||
} | ||
} | ||
|
||
logger.ok(`Successfully deleted comment!`); | ||
logger.verbose(`Exiting deleteComments`); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { Context } from "../types"; | ||
|
||
export async function updateComment(context: Context) { | ||
const { | ||
logger, | ||
payload, | ||
adapters: { supabase }, | ||
} = context; | ||
|
||
const sender = payload.comment.user?.login; | ||
const repo = payload.repository.name; | ||
const issueNumber = payload.issue.number; | ||
const owner = payload.repository.owner.login; | ||
const body = payload.comment.body; | ||
|
||
// Log the payload | ||
logger.debug(`Executing updateComment:`, { sender, repo, issueNumber, owner }); | ||
|
||
// Fetch the previous comment and update it in the db | ||
try { | ||
await supabase.comment.updateComment(body, payload.comment.id); | ||
} catch (error) { | ||
if (error instanceof Error) { | ||
logger.error(`Error updating comment:`, { error: error, stack: error.stack }); | ||
throw error; | ||
} else { | ||
logger.error(`Error updating comment:`, { err: error, error: new Error() }); | ||
throw error; | ||
} | ||
} | ||
|
||
logger.ok(`Successfully updated comment!`); | ||
logger.verbose(`Exiting updateComment`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.