diff --git a/src/adapters/supabase/helpers/comment.ts b/src/adapters/supabase/helpers/comment.ts index d09f24a..ea67958 100644 --- a/src/adapters/supabase/helpers/comment.ts +++ b/src/adapters/supabase/helpers/comment.ts @@ -31,9 +31,11 @@ export class Comment extends SuperSupabase { } return data; } - async findSimilarComments(query: string, threshold: number, currentId: string): Promise { const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: query, prompt: "This is a query for the stored documents:" }); + //Escape the any special characters in the query for use in the SQL query + query = query.replace(/'/g, "''").replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "\\%").replace(/_/g, "\\_"); + this.context.logger.info(`Query: ${query}`); const { data, error } = await this.supabase.rpc("find_similar_comments", { current_id: currentId, query_text: query, diff --git a/src/adapters/supabase/helpers/issues.ts b/src/adapters/supabase/helpers/issues.ts index 142ef02..8635539 100644 --- a/src/adapters/supabase/helpers/issues.ts +++ b/src/adapters/supabase/helpers/issues.ts @@ -34,6 +34,7 @@ export class Issue extends SuperSupabase { } async findSimilarIssues(plaintext: string, threshold: number, currentId: string): Promise { const embedding = await this.context.adapters.voyage.embedding.createEmbedding({ text: plaintext, prompt: "This is a query for the stored documents:" }); + plaintext = plaintext.replace(/'/g, "''").replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/%/g, "\\%").replace(/_/g, "\\_"); const { data, error } = await this.supabase.rpc("find_similar_issue_ftse", { current_id: currentId, query_text: plaintext, diff --git a/src/handlers/comments.ts b/src/handlers/comments.ts index cf12053..d7e2d0f 100644 --- a/src/handlers/comments.ts +++ b/src/handlers/comments.ts @@ -76,7 +76,6 @@ export function streamlineComments(comments: SimplifiedComment[]) { if (user?.type === "Bot") continue; const key = createKey(url); const [owner, repo] = splitKey(key); - if (!streamlined[key]) { streamlined[key] = []; } diff --git a/src/helpers/format-chat-history.ts b/src/helpers/format-chat-history.ts index 5c92c63..aadd7f3 100644 --- a/src/helpers/format-chat-history.ts +++ b/src/helpers/format-chat-history.ts @@ -140,9 +140,9 @@ function createComment(comment: StreamlinedComments) { return ""; } // Remove duplicates - const uniqueComments = comment.comments.filter((c, i, a) => a.findIndex((cc) => cc.id === c.id) === i); + //const uniqueComments = comment.comments.filter((c, i, a) => a.findIndex((cc) => cc.id === c.id) === i); // Format comments - const formattedComments = uniqueComments.map((c) => `${c.id} ${c.user}: ${c.body}\n`); + const formattedComments = comment.comments.map((c) => `${c.id} ${c.user}: ${c.body}\n`); return formattedComments.join(""); } diff --git a/src/helpers/issue-fetching.ts b/src/helpers/issue-fetching.ts index 486d83e..fc1df5a 100644 --- a/src/helpers/issue-fetching.ts +++ b/src/helpers/issue-fetching.ts @@ -87,7 +87,6 @@ export async function fetchLinkedIssues(params: FetchParams) { for (const comment of comments) { const foundIssues = idIssueFromComment(comment.body); const foundCodes = comment.body ? await fetchCodeLinkedFromIssue(comment.body, params.context, comment.issueUrl) : []; - if (foundIssues) { for (const linkedIssue of foundIssues) { const linkedKey = createKey(linkedIssue.url, linkedIssue.issueNumber); diff --git a/src/helpers/issue.ts b/src/helpers/issue.ts index 2c76179..cc67b2a 100644 --- a/src/helpers/issue.ts +++ b/src/helpers/issue.ts @@ -144,7 +144,6 @@ export async function fetchCodeLinkedFromIssue( path: parsedUrl.path, }); } - if ("content" in response.data) { const content = Buffer.from(response.data.content, "base64").toString(); return { body: content, id: parsedUrl.path }; @@ -163,7 +162,9 @@ export async function fetchCodeLinkedFromIssue( repo: context.payload.repository.name, issueNumber: parseInt(issue.match(/\/issues\/(\d+)/)?.[1] || "0", 10), issueUrl: url, - user: null, + user: { + ...context.payload.sender, + }, })); } diff --git a/src/main.ts b/src/main.ts index 62e2875..32b3828 100644 --- a/src/main.ts +++ b/src/main.ts @@ -25,7 +25,6 @@ export async function run() { authToken: payload.authToken, ref: payload.ref, }; - await plugin(inputs, env); } diff --git a/src/types/github-types.d.ts b/src/types/github-types.d.ts index 55e3824..23a0b18 100644 --- a/src/types/github-types.d.ts +++ b/src/types/github-types.d.ts @@ -27,7 +27,7 @@ export type LinkedIssues = { }; export type SimplifiedComment = { - user: User | null; + user: User | Partial; body: string; id: string; org: string; @@ -37,7 +37,7 @@ export type SimplifiedComment = { export type FetchedCodes = { body: string; - user: User | null; + user: User | Partial; issueUrl: string; id: string; org: string;