Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Issue dedup relevance #26

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions src/handlers/issue-deduplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export interface IssueGraphqlResponse {
node: {
title: string;
url: string;
repository: {
name: string;
owner: {
login: string;
};
};
};
similarity: string;
}
Expand All @@ -24,7 +30,6 @@ export async function issueChecker(context: Context): Promise<boolean> {
const { payload } = context as { payload: IssuePayload };
const issue = payload.issue;
const issueContent = issue.body + issue.title;

// Fetch all similar issues based on settings.warningThreshold
const similarIssues = await supabase.issue.findSimilarIssues(issueContent, context.config.warningThreshold, issue.node_id);
if (similarIssues && similarIssues.length > 0) {
Expand Down Expand Up @@ -53,6 +58,18 @@ export async function issueChecker(context: Context): Promise<boolean> {
return false;
}

/**
* Compare the repository and issue name to the similar issue repository and issue name
* @param repoOrg
* @param similarIssueRepoOrg
* @param repoName
* @param similarIssueRepoName
* @returns
*/
function matchRepoOrgToSimilarIssueRepoOrg(repoOrg: string, similarIssueRepoOrg: string, repoName: string, similarIssueRepoName: string): boolean {
return repoOrg === similarIssueRepoOrg && repoName === similarIssueRepoName;
}

/**
* Handle commenting on an issue with similar issues information
* @param context
Expand All @@ -69,42 +86,46 @@ async function handleSimilarIssuesComment(context: Context, payload: IssuePayloa
... on Issue {
title
url
repository {
name
owner {
login
}
}
}
}
}`,
{ issueNodeId: issue.issue_id }
);
issueUrl.similarity = (issue.similarity * 100).toFixed(2);
issueUrl.similarity = Math.round(issue.similarity * 100).toString();
return issueUrl;
})
);

const commentBody = issueList.map((issue) => `- [${issue.node.title}](${issue.node.url}) Similarity: ${issue.similarity}`).join("\n");
const body = `This issue seems to be similar to the following issue(s):\n\n${commentBody}`;
let finalIdx = 0;
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
const commentBody = issueList
.filter((issue) =>
matchRepoOrgToSimilarIssueRepoOrg(payload.repository.owner.login, issue.node.repository.owner.login, payload.repository.name, issue.node.repository.name)
)
.map((issue, index) => {
const modifiedUrl = issue.node.url.replace("https://github.com", "https://www.github.com");
finalIdx += 1;
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
return `[^0${index + 1}^]: [${issue.node.title}](${modifiedUrl}) ${issue.similarity}%`;
})
.join("\n");
const footnoteLinks = [...Array(finalIdx).keys()].map((i) => `[^0${i + 1}^]`).join("");
0x4007 marked this conversation as resolved.
Show resolved Hide resolved
const body = "\n###### Similar " + footnoteLinks + ":\n\n" + commentBody;
0x4007 marked this conversation as resolved.
Show resolved Hide resolved

const existingComments = await context.octokit.issues.listComments({
// Remove the existing foot note
const existingBody = context.payload.issue.body;
const footnoteIndex = existingBody?.indexOf("\n###### Similar");
const newBody = footnoteIndex !== -1 ? existingBody?.substring(0, footnoteIndex) : existingBody;

//Append the new foot note
await context.octokit.issues.update({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: issueNumber,
body: newBody + body,
});

const existingComment = existingComments.data.find(
(comment) => comment.body && comment.body.includes("This issue seems to be similar to the following issue(s)")
);

if (existingComment) {
await context.octokit.issues.updateComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
comment_id: existingComment.id,
body: body,
});
} else {
await context.octokit.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
issue_number: issueNumber,
body: body,
});
}
}
18 changes: 18 additions & 0 deletions supabase/migrations/20241002004403_issue_comments.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CREATE OR REPLACE FUNCTION find_similar_issues(current_id VARCHAR, query_embedding vector(1024), threshold float8)
RETURNS TABLE(issue_id VARCHAR, issue_plaintext TEXT, similarity float8) AS $$
DECLARE
current_quantized vector(1024);
BEGIN
-- Ensure the query_embedding is in the correct format
current_quantized := query_embedding;
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 1 - (l2_distance(current_quantized, embedding)) > threshold
ORDER BY similarity;
END;
$$ LANGUAGE plpgsql;
4 changes: 2 additions & 2 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ function createContextInner(
} as Context["payload"],
config: {
warningThreshold: 0.75,
matchThreshold: 0.95,
jobMatchingThreshold: 0.95,
matchThreshold: 0.9,
jobMatchingThreshold: 0.75,
},
adapters: {} as Context["adapters"],
logger: new Logs("debug"),
Expand Down