Skip to content

Commit

Permalink
fix: issue dedup
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Nov 9, 2024
1 parent bf23b09 commit 979e34a
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/handlers/issue-deduplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ export async function issueChecker(context: Context): Promise<boolean> {
issueBody = removeFootnotes(issueBody);
const similarIssues = await supabase.issue.findSimilarIssues(issue.title + removeFootnotes(issueBody), 0.7, issue.node_id);
if (similarIssues && similarIssues.length > 0) {
const processedIssues = await processSimilarIssues(similarIssues, context, issueBody);
let processedIssues = await processSimilarIssues(similarIssues, context, issueBody);
processedIssues = processedIssues.filter((issue) =>
matchRepoOrgToSimilarIssueRepoOrg(payload.repository.owner.login, issue.node.repository.owner.login, payload.repository.name, issue.node.repository.name)
);
const matchIssues = processedIssues.filter((issue) => parseFloat(issue.similarity) >= context.config.matchThreshold);
if (matchIssues.length > 0) {
logger.info(`Similar issue which matches more than ${context.config.matchThreshold} already exists`);
Expand Down Expand Up @@ -130,15 +133,13 @@ function findMostSimilarSentence(issueContent: string, similarIssueContent: stri
return { sentence: mostSimilarSentence, similarity: maxSimilarity, index: mostSimilarIndex };
}

async function handleSimilarIssuesComment(context: Context, payload: IssuePayload, issueBody: string, issueNumber: number, issueList: IssueGraphqlResponse[]) {
const relevantIssues = issueList.filter((issue) =>
matchRepoOrgToSimilarIssueRepoOrg(payload.repository.owner.login, issue.node.repository.owner.login, payload.repository.name, issue.node.repository.name)
);

if (relevantIssues.length === 0) {
context.logger.info("No relevant issues found with the same repository and organization");
}

async function handleSimilarIssuesComment(
context: Context,
payload: IssuePayload,
issueBody: string,
issueNumber: number,
relevantIssues: IssueGraphqlResponse[]
) {
if (!issueBody) {
return;
}
Expand Down Expand Up @@ -183,17 +184,8 @@ async function handleMatchIssuesComment(
context: Context,
payload: IssuePayload,
issueBody: string,
issueList: IssueGraphqlResponse[]
relevantIssues: IssueGraphqlResponse[]
): Promise<string | undefined> {
const relevantIssues = issueList.filter((issue) =>
matchRepoOrgToSimilarIssueRepoOrg(payload.repository.owner.login, issue.node.repository.owner.login, payload.repository.name, issue.node.repository.name)
);

if (relevantIssues.length === 0) {
context.logger.info("No relevant issues found with the same repository and organization");
return;
}

if (!issueBody) {
return;
}
Expand Down Expand Up @@ -293,9 +285,15 @@ export function removeFootnotes(content: string): string {
contentWithoutFootnotes = contentWithoutFootnotes.replace(new RegExp(`\\[\\^${footnoteNumber}\\^\\]`, "g"), "");
});
}
contentWithoutFootnotes = removeCautionMessages(contentWithoutFootnotes);
return contentWithoutFootnotes;
}

export function removeCautionMessages(content: string): string {
const cautionRegex = />[!CAUTION]\n> This issue may be a duplicate of the following issues:\n((> - \[[^\]]+\]\([^)]+\)\n)+)/g;
return content.replace(cautionRegex, "");
}

function checkIfDuplicateFootNoteExists(content: string): boolean {
const footnoteDefRegex = /\[\^(\d+)\^\]: ⚠ \d+% possible duplicate - [^\n]+(\n|$)/g;
const footnotes = content.match(footnoteDefRegex);
Expand Down

0 comments on commit 979e34a

Please sign in to comment.