Skip to content

Commit

Permalink
fix: comments and issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Oct 19, 2024
1 parent 4d9e674 commit ae5f552
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/adapters/supabase/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export class Comment extends SuperSupabase {
}
return data;
}

async findSimilarComments(query: string, threshold: number, currentId: string): Promise<CommentSimilaritySearchResult[] | null> {
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,
Expand Down
1 change: 1 addition & 0 deletions src/adapters/supabase/helpers/issues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export class Issue extends SuperSupabase {
}
async findSimilarIssues(plaintext: string, threshold: number, currentId: string): Promise<IssueSimilaritySearchResult[] | null> {
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,
Expand Down
1 change: 0 additions & 1 deletion src/handlers/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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] = [];
}
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/format-chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("");
}

Expand Down
1 change: 0 additions & 1 deletion src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions src/helpers/issue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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,
},
}));
}

Expand Down
1 change: 0 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function run() {
authToken: payload.authToken,
ref: payload.ref,
};

await plugin(inputs, env);
}

Expand Down
4 changes: 2 additions & 2 deletions src/types/github-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type LinkedIssues = {
};

export type SimplifiedComment = {
user: User | null;
user: User | Partial<User>;
body: string;
id: string;
org: string;
Expand All @@ -37,7 +37,7 @@ export type SimplifiedComment = {

export type FetchedCodes = {
body: string;
user: User | null;
user: User | Partial<User>;
issueUrl: string;
id: string;
org: string;
Expand Down

0 comments on commit ae5f552

Please sign in to comment.