From 8e8da2cb5c7925c752953240706846b367366281 Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Thu, 3 Oct 2024 10:35:18 -0400 Subject: [PATCH 1/2] fix: empty footnotes --- src/handlers/issue-deduplication.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/handlers/issue-deduplication.ts b/src/handlers/issue-deduplication.ts index abea2ea..506d271 100644 --- a/src/handlers/issue-deduplication.ts +++ b/src/handlers/issue-deduplication.ts @@ -112,6 +112,10 @@ async function handleSimilarIssuesComment(context: Context, payload: IssuePayloa return `[^0${index + 1}^]: [${issue.node.title}](${modifiedUrl}) ${issue.similarity}%`; }) .join("\n"); + + if (commentBody.length === 0) { + return; + } const footnoteLinks = [...Array(++finalIndex).keys()].map((i) => `[^0${i + 1}^]`).join(""); const body = "\n###### Similar " + footnoteLinks + "\n\n" + commentBody; From 4582a1463b82d0c61d1c68d3b8cda53ba14cf0ea Mon Sep 17 00:00:00 2001 From: Shivaditya Shivganesh Date: Thu, 3 Oct 2024 11:57:57 -0400 Subject: [PATCH 2/2] fix: similar issue filter --- src/handlers/issue-deduplication.ts | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/handlers/issue-deduplication.ts b/src/handlers/issue-deduplication.ts index 506d271..599b378 100644 --- a/src/handlers/issue-deduplication.ts +++ b/src/handlers/issue-deduplication.ts @@ -29,7 +29,13 @@ export async function issueChecker(context: Context): Promise { } = context; const { payload } = context as { payload: IssuePayload }; const issue = payload.issue; - const issueContent = issue.body + issue.title; + + //Find and remove the footnotes from the issue content + const existingBody = context.payload.issue.body; + const footnoteIndex = existingBody?.indexOf("\n###### Similar"); + const issueBody = footnoteIndex !== -1 ? existingBody?.substring(0, footnoteIndex) : existingBody; + const issueContent = issueBody + 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) { @@ -50,7 +56,7 @@ export async function issueChecker(context: Context): Promise { // Handle issues that match the settings.warningThreshold but not the MATCH_THRESHOLD if (similarIssues.length > 0) { logger.info(`Similar issue which matches more than ${context.config.warningThreshold} already exists`); - await handleSimilarIssuesComment(context, payload, issue.number, similarIssues); + await handleSimilarIssuesComment(context, payload, issue.number, similarIssues, issueBody || ""); return true; } } @@ -77,7 +83,13 @@ function matchRepoOrgToSimilarIssueRepoOrg(repoOrg: string, similarIssueRepoOrg: * @param issueNumber * @param similarIssues */ -async function handleSimilarIssuesComment(context: Context, payload: IssuePayload, issueNumber: number, similarIssues: IssueSimilaritySearchResult[]) { +async function handleSimilarIssuesComment( + context: Context, + payload: IssuePayload, + issueNumber: number, + similarIssues: IssueSimilaritySearchResult[], + modifiedBody: string +) { const issueList: IssueGraphqlResponse[] = await Promise.all( similarIssues.map(async (issue: IssueSimilaritySearchResult) => { const issueUrl: IssueGraphqlResponse = await context.octokit.graphql( @@ -119,16 +131,11 @@ async function handleSimilarIssuesComment(context: Context, payload: IssuePayloa const footnoteLinks = [...Array(++finalIndex).keys()].map((i) => `[^0${i + 1}^]`).join(""); const body = "\n###### Similar " + footnoteLinks + "\n\n" + commentBody; - // 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, + body: modifiedBody + body, }); }