Skip to content

Commit

Permalink
fix: similar issue search
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Nov 26, 2024
1 parent db605eb commit 451530d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 42 deletions.
46 changes: 26 additions & 20 deletions src/handlers/issue-deduplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,32 +220,38 @@ async function handleMatchIssuesComment(

// Process similar issues and return the list of similar issues with their similarity scores
async function processSimilarIssues(similarIssues: IssueSimilaritySearchResult[], context: Context, issueBody: string): Promise<IssueGraphqlResponse[]> {
return await Promise.all(
const processedIssues = await Promise.all(
similarIssues.map(async (issue: IssueSimilaritySearchResult) => {
const issueUrl: IssueGraphqlResponse = await context.octokit.graphql(
`query($issueNodeId: ID!) {
node(id: $issueNodeId) {
... on Issue {
title
url
number
body
repository {
name
owner {
login
try {
const issueUrl: IssueGraphqlResponse = await context.octokit.graphql(
`query($issueNodeId: ID!) {
node(id: $issueNodeId) {
... on Issue {
title
url
number
body
repository {
name
owner {
login
}
}
}
}
}
}`,
{ issueNodeId: issue.issue_id }
);
issueUrl.similarity = Math.round(issue.similarity * 100).toString();
issueUrl.mostSimilarSentence = findMostSimilarSentence(issueBody, issueUrl.node.body, context);
return issueUrl;
}`,
{ issueNodeId: issue.issue_id }
);
issueUrl.similarity = Math.round(issue.similarity * 100).toString();
issueUrl.mostSimilarSentence = findMostSimilarSentence(issueBody, issueUrl.node.body, context);
return issueUrl;
} catch (error) {
context.logger.error(`Failed to fetch issue ${issue.issue_id}: ${error}`, { issue });
return null;
}
})
);
return processedIssues.filter((issue): issue is IssueGraphqlResponse => issue !== null);
}

/**
Expand Down
49 changes: 27 additions & 22 deletions src/handlers/issue-matching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,36 +50,41 @@ export async function issueMatching(context: Context<"issues.opened" | "issues.e
if (similarIssues && similarIssues.length > 0) {
similarIssues.sort((a: IssueSimilaritySearchResult, b: IssueSimilaritySearchResult) => b.similarity - a.similarity); // Sort by similarity
const fetchPromises = similarIssues.map(async (issue: IssueSimilaritySearchResult) => {
const issueObject: IssueGraphqlResponse = await context.octokit.graphql(
`query ($issueNodeId: ID!) {
try {
const issueObject: IssueGraphqlResponse = await context.octokit.graphql(
`query ($issueNodeId: ID!) {
node(id: $issueNodeId) {
... on Issue {
title
url
state
repository{
name
... on Issue {
title
url
state
repository{
name
owner {
login
}
}
stateReason
closed
assignees(first: 10) {
nodes {
login
url
}
}
stateReason
closed
assignees(first: 10) {
nodes {
login
url
}
}
}
}`,
{ issueNodeId: issue.issue_id }
);
issueObject.similarity = issue.similarity;
return issueObject;
}
}`,
{ issueNodeId: issue.issue_id }
);
issueObject.similarity = issue.similarity;
return issueObject;
} catch (error) {
context.logger.error(`Failed to fetch issue ${issue.issue_id}: ${error}`, { issue });
return null;
}
});
const issueList = await Promise.all(fetchPromises);
const issueList = (await Promise.all(fetchPromises)).filter((issue) => issue !== null);
issueList.forEach((issue: IssueGraphqlResponse) => {
if (issue.node.closed && issue.node.stateReason === "COMPLETED" && issue.node.assignees.nodes.length > 0) {
const assignees = issue.node.assignees.nodes;
Expand Down

0 comments on commit 451530d

Please sign in to comment.