-
Notifications
You must be signed in to change notification settings - Fork 7
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: returnDataToKernel #44
base: development
Are you sure you want to change the base?
Changes from all commits
f98edee
90cfcc3
2feb5d5
b09533a
e25ad42
a76b34d
a4815c9
5422521
f9c4862
ed884fd
bf23b09
979e34a
f698377
98c58cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,11 @@ 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 matchIssues = similarIssues.filter((issue) => issue.similarity >= context.config.matchThreshold); | ||
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`); | ||
//To the issue body, add a footnote with the link to the similar issue | ||
|
@@ -58,7 +61,7 @@ export async function issueChecker(context: Context): Promise<boolean> { | |
}); | ||
return true; | ||
} | ||
if (similarIssues.length > 0) { | ||
if (processedIssues.length > 0) { | ||
logger.info(`Similar issue which matches more than ${context.config.warningThreshold} already exists`); | ||
await handleSimilarIssuesComment(context, payload, issueBody, issue.number, processedIssues); | ||
return true; | ||
|
@@ -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; | ||
} | ||
|
@@ -183,16 +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"); | ||
} | ||
|
||
if (!issueBody) { | ||
return; | ||
} | ||
|
@@ -292,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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are these checks? Seems like wrong approach to be doing this. I would expect you should be able to select the right data in the first place and process less comments with a better strategy, although I don't understand the full context of this process here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These checks are in place to avoid generating embeddings for comment or issue bodies that include footnotes or caution messages. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just ignore every bot comment is my point There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but when the user updates an issue, it includes footnotes and a caution statement. Should these be propagated to the database as well? I think bot actions are ignored by the kernel. |
||
return content.replace(cautionRegex, ""); | ||
} | ||
|
||
function checkIfDuplicateFootNoteExists(content: string): boolean { | ||
const footnoteDefRegex = /\[\^(\d+)\^\]: ⚠ \d+% possible duplicate - [^\n]+(\n|$)/g; | ||
const footnotes = content.match(footnoteDefRegex); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to just throw this, then it logs and halts function execution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand what you're suggesting. Are you asking if I should log a fatal error instead of throwing a new one to halt the function execution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gentlementlegen rfc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just
throw logger.fatal
so you get the log displayed and the error caught on a higher level of execution.