Skip to content

Commit

Permalink
fix: issue creation fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Oct 8, 2024
1 parent 75af465 commit a184884
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/handlers/issue-deduplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface IssueGraphqlResponse {

/**
* Checks if the current issue is a duplicate of an existing issue.
* If a similar issue is found, a comment is added to the current issue.
* If a similar issue is found, a footnote is added to the current issue.
* @param context The context object
* @returns True if a similar issue is found, false otherwise
**/
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export async function runPlugin(context: Context) {
} else if (isIssueEvent(context)) {
switch (eventName) {
case "issues.opened":
await issueChecker(context);
await addIssue(context);
await issueChecker(context);
return await issueMatching(context);
case "issues.edited":
await issueChecker(context);
Expand Down
38 changes: 38 additions & 0 deletions supabase/migrations/20241008175109_function_issue.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
DROP FUNCTION IF EXISTS find_similar_issues;

CREATE OR REPLACE FUNCTION find_similar_issues(current_id VARCHAR, query_embedding vector(1024), threshold float8, top_k INT)
RETURNS TABLE(issue_id VARCHAR, issue_plaintext TEXT, similarity float8) AS $$
DECLARE
current_quantized vector(1024);
current_repo TEXT;
current_org TEXT;
BEGIN
-- Ensure the query_embedding is in the correct format
current_quantized := query_embedding;

-- Extract the current issue's repo and org from the payload
SELECT
payload->'repository'->>'name'::text,
payload->'repository'->'owner'->>'login'::text
INTO current_repo, current_org
FROM issues
WHERE id = current_id;

-- Check if the current issue has valid repo and org
IF current_repo IS NULL OR current_org IS NULL THEN
RETURN; -- Exit if current issue's repo or org is null
END IF;

RETURN QUERY
SELECT id AS issue_id,
plaintext AS issue_plaintext,
1 - (l2_distance(current_quantized, embedding)) AS similarity
FROM issues
WHERE id <> current_id
AND current_repo = payload->'repository'->>'name'::text
AND current_org = payload->'repository'->'owner'->>'login'::text
AND 1 - l2_distance(current_quantized, embedding) > threshold -- Ensure similarity exceeds threshold
ORDER BY similarity DESC
LIMIT top_k;
END;
$$ LANGUAGE plpgsql;

0 comments on commit a184884

Please sign in to comment.