generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat: Issue Deduplication #11
Merged
0x4007
merged 8 commits into
ubiquity-os-marketplace:development
from
sshivaditya2019:development
Sep 16, 2024
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
da877f7
chore: updated generated Supabase types
github-actions[bot] 2a08b22
feat: issue dedup
sshivaditya 736a0bf
fix: cspell
sshivaditya fe17b3e
fix: knip
sshivaditya 4d6491a
fix: remove label controls and issue reopen controls, added similarit…
sshivaditya 33a5f93
fix: similarity in percents
sshivaditya 72d72a3
fix: issue dedup warning threshold to 75
sshivaditya 7609943
feat: pass config through plugin settings
sshivaditya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { IssueSimilaritySearchResult } from "../adapters/supabase/helpers/issues"; | ||
import { Context } from "../types"; | ||
const MATCH_THRESHOLD = 0.95; | ||
const WARNING_THRESHOLD = 0.5; | ||
|
||
export interface IssueGraphqlResponse { | ||
node: { | ||
title: string; | ||
url: string; | ||
}; | ||
} | ||
|
||
/** | ||
* Check if an issue is similar to any existing issues in the database | ||
* @param context | ||
* @returns true if the issue is similar to an existing issue, false otherwise | ||
*/ | ||
export async function issueChecker(context: Context): Promise<boolean> { | ||
const { | ||
logger, | ||
payload, | ||
adapters: { supabase }, | ||
} = context; | ||
|
||
const issue = payload.issue; | ||
|
||
//First Check if an issue with more than MATCH_THRESHOLD similarity exists (Very Similar) | ||
const similarIssue = await supabase.issue.findSimilarIssues(issue.body + issue.title, MATCH_THRESHOLD, issue.node_id); | ||
if (similarIssue && similarIssue?.length > 0) { | ||
logger.info(`Similar issue which matches more than ${MATCH_THRESHOLD} already exists`); | ||
sshivaditya2019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//Close the issue as "unplanned" | ||
await context.octokit.issues.update({ | ||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
issue_number: issue.number, | ||
state: "closed", | ||
labels: ["unplanned"], | ||
sshivaditya2019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
return true; | ||
} | ||
|
||
//Second Check if an issue with more than WARNING_THRESHOLD similarity exists (Warning) | ||
const warningIssue = await supabase.issue.findSimilarIssues(issue.body + issue.title, WARNING_THRESHOLD, issue.node_id); | ||
if (warningIssue && warningIssue?.length > 0) { | ||
logger.info(`Similar issue which matches more than ${WARNING_THRESHOLD} already exists`); | ||
//Add a comment immediately next to the issue | ||
//Build a list of similar issues url | ||
const issueList: IssueGraphqlResponse[] = await Promise.all( | ||
warningIssue.map(async (issue: IssueSimilaritySearchResult) => { | ||
//fetch the issue url and title using globalNodeId | ||
const issueUrl: IssueGraphqlResponse = await context.octokit.graphql( | ||
`query($issueNodeId: ID!) { | ||
node(id: $issueNodeId) { | ||
... on Issue { | ||
title | ||
url | ||
} | ||
} | ||
}`, | ||
{ | ||
issueNodeId: issue.issue_id, | ||
} | ||
); | ||
return issueUrl; | ||
}) | ||
); | ||
|
||
// Reopen the issue | ||
sshivaditya2019 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await context.octokit.issues.update({ | ||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
issue_number: issue.number, | ||
state: "open", | ||
}); | ||
//Remove the "unplanned" label | ||
await context.octokit.issues.removeLabel({ | ||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
issue_number: issue.number, | ||
name: "unplanned", | ||
}); | ||
// Check if there is already a comment on the issue | ||
const existingComment = await context.octokit.issues.listComments({ | ||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
issue_number: issue.number, | ||
}); | ||
if (existingComment.data.length > 0) { | ||
// Find the comment that lists the similar issues | ||
const commentToUpdate = existingComment.data.find( | ||
(comment) => comment && comment.body && comment.body.includes("This issue seems to be similar to the following issue(s)") | ||
); | ||
|
||
if (commentToUpdate) { | ||
// Update the comment with the latest list of similar issues | ||
const body = issueList.map((issue) => `- [${issue.node.title}](${issue.node.url})`).join("\n"); | ||
const updatedBody = `This issue seems to be similar to the following issue(s):\n\n${body}`; | ||
await context.octokit.issues.updateComment({ | ||
owner: payload.repository.owner.login, | ||
repo: payload.repository.name, | ||
comment_id: commentToUpdate.id, | ||
body: updatedBody, | ||
}); | ||
} else { | ||
// Add a new comment to the issue | ||
await createNewComment(context, issueList); | ||
} | ||
} else { | ||
// Add a new comment to the issue | ||
await createNewComment(context, issueList); | ||
} | ||
return true; | ||
} | ||
|
||
logger.info("No similar issue found"); | ||
return false; | ||
} | ||
|
||
/** | ||
* Create a new comment on the issue with the list of similar issues | ||
* @param context | ||
* @param resolvedIssueList | ||
*/ | ||
async function createNewComment(context: Context, resolvedIssueList: IssueGraphqlResponse[]) { | ||
let body = "This issue seems to be similar to the following issue(s):\n\n"; | ||
resolvedIssueList.forEach((issue) => { | ||
const issueLine = `- [${issue.node.title}](${issue.node.url})\n`; | ||
body += issueLine; | ||
}); | ||
await context.octokit.issues.createComment({ | ||
owner: context.payload.repository.owner.login, | ||
repo: context.payload.repository.name, | ||
issue_number: context.payload.issue.number, | ||
body: body, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why did you do 50%?
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.
A cosine similarity of 0.75 appears quite close for identifying similar issues. I tested this with a few examples and noticed some potential errors with the samples. Typically, for similar issues, the similarity was either above 75% and aligned with 95% category or around 60%. Therefore, I experimented with a 50% threshold, which seemed to work well.