Skip to content

Commit

Permalink
fix: ground truth errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Jan 6, 2025
1 parent dda18bf commit ef0b815
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 38 deletions.
95 changes: 57 additions & 38 deletions src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Context } from "../types";
import { FetchParams, Issue, LinkedIssues, SimplifiedComment, PullRequestDetails } from "../types/github-types";
import { FetchParams, Issue, LinkedIssues, SimplifiedComment, PullRequestDetails, TreeNode } from "../types/github-types";
import { StreamlinedComment, TokenLimits } from "../types/llm";
import { fetchCodeLinkedFromIssue, idIssueFromComment, mergeStreamlinedComments } from "./issue";
import { handleSpec } from "./issue-handling";
Expand Down Expand Up @@ -150,55 +150,61 @@ export interface RecursiveIssueSearchResult {
>;
}

function createTreeNode(issue: Issue, params: FetchParams, depth: number): TreeNode {
return {
issue: {
body: issue.body || "",
owner: params.owner || params.context.payload.repository.owner.login,
repo: params.repo || params.context.payload.repository.name,
issueNumber: params.issueNum || params.context.payload.issue.number,
url: issue.html_url,
comments: [],
prDetails: issue.prDetails,
},
children: [],
depth,
status: "pending",
metadata: {
processedAt: new Date(),
commentCount: 0,
linkedIssuesCount: 0,
hasCodeReferences: false,
},
};
}

export async function recursivelyFetchLinkedIssues(params: FetchParams): Promise<RecursiveIssueSearchResult> {
const maxDepth = params.maxDepth || 15;
const _currentDepth = params.currentDepth || 0;

// Initialize tree structure with main issue as root
const issueTree: Record<
string,
{
issue: EnhancedLinkedIssues;
children: string[];
depth: number;
parent?: string;
}
> = {};
const issueTree: Record<string, TreeNode> = {};
const seen = new Set<string>();
const linkedIssues: LinkedIssues[] = [];
const specAndBodies: Record<string, string> = {};
const streamlinedComments: Record<string, StreamlinedComment[]> = {};

// Fetch the main issue first
// Initialize with main issue
const mainIssue = await fetchIssue(params);
if (!mainIssue) {
return { linkedIssues: [], specAndBodies: {}, streamlinedComments: {}, issueTree };
}

// Create the root node for the main issue
const mainIssueKey = `${params.owner || params.context.payload.repository.owner.login}/${params.repo || params.context.payload.repository.name}/${params.issueNum || params.context.payload.issue.number}`;
const mainIssueKey = `${params.owner || params.context.payload.repository.owner.login}/${
params.repo || params.context.payload.repository.name
}/${params.issueNum || params.context.payload.issue.number}`;

// Get comments and linked issues for the main issue/PR
const { comments, linkedIssues: initialLinkedIssues } = await fetchIssueComments(params);
// Initialize root node
issueTree[mainIssueKey] = createTreeNode(mainIssue, params, 0);
seen.add(mainIssueKey);
linkedIssues.push(issueTree[mainIssueKey].issue);

issueTree[mainIssueKey] = {
issue: {
body: mainIssue.body || "",
owner: params.owner || params.context.payload.repository.owner.login,
repo: params.repo || params.context.payload.repository.name,
issueNumber: params.issueNum || params.context.payload.issue.number,
url: mainIssue.html_url,
comments,
prDetails: mainIssue.prDetails,
},
children: [],
depth: 0,
};

// Process all comments to find linked issues
const linkedIssues: LinkedIssues[] = [issueTree[mainIssueKey].issue];
const specAndBodies: Record<string, string> = {};
const seen = new Set<string>([mainIssueKey]);
const streamlinedComments: Record<string, StreamlinedComment[]> = {};
// Get initial comments and linked issues
const { comments, linkedIssues: initialLinkedIssues } = await fetchIssueComments(params);
if (comments) {
issueTree[mainIssueKey].issue.comments = comments;
}

// Add initial linked issues from PR if any
if (initialLinkedIssues.length > 0) {
if (initialLinkedIssues && initialLinkedIssues.length > 0) {
for (const linkedIssue of initialLinkedIssues) {
const linkedKey = `${linkedIssue.owner}/${linkedIssue.repo}/${linkedIssue.issueNumber}`;
if (!seen.has(linkedKey)) {
Expand All @@ -210,6 +216,13 @@ export async function recursivelyFetchLinkedIssues(params: FetchParams): Promise
children: [],
depth: 1,
parent: mainIssueKey,
status: "pending",
metadata: {
processedAt: new Date(),
commentCount: linkedIssue.comments?.length || 0,
linkedIssuesCount: 0,
hasCodeReferences: false,
},
};
}
}
Expand Down Expand Up @@ -258,7 +271,6 @@ export async function recursivelyFetchLinkedIssues(params: FetchParams): Promise

if (!fetchedIssue || !fetchedIssue.body) continue;

// Add to tree structure
issueTree[foundKey] = {
issue: {
body: fetchedIssue.body,
Expand All @@ -272,6 +284,13 @@ export async function recursivelyFetchLinkedIssues(params: FetchParams): Promise
children: [],
depth: current.depth + 1,
parent: current.key,
status: "pending",
metadata: {
processedAt: new Date(),
commentCount: fetchedComments?.length || 0,
linkedIssuesCount: 0,
hasCodeReferences: false,
},
};
issueTree[current.key].children.push(foundKey);

Expand Down
42 changes: 42 additions & 0 deletions src/types/github-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RestEndpointMethodTypes } from "@octokit/rest";
import { Context } from "./context";
import { StreamlinedComment } from "./llm";

type BaseIssue = RestEndpointMethodTypes["issues"]["get"]["response"]["data"];
export interface Issue extends BaseIssue {
Expand Down Expand Up @@ -90,6 +91,7 @@ export interface LinkedIssues {
body: string | undefined | null;
prDetails?: PullRequestDetails;
readme?: string;
referenceType?: "closing" | "depends" | "direct";
}

export type SimplifiedComment = {
Expand All @@ -110,3 +112,43 @@ export type FetchedCodes = {
repo: string;
issueNumber: number;
};

export interface TreeNode {
issue: LinkedIssues;
children: string[];
depth: number;
parent?: string;
status: "pending" | "processed" | "error";
errorReason?: string;
metadata: {
processedAt: Date;
fetchDuration?: number;
commentCount: number;
linkedIssuesCount: number;
hasCodeReferences: boolean;
};
}

export interface TreeProcessingQueue {
key: string;
depth: number;
parent?: string;
priority: number;
}

export interface ProcessingContext {
params: FetchParams;
issueTree: Record<string, TreeNode>;
seen: Set<string>;
processingQueue: TreeProcessingQueue[];
linkedIssues: LinkedIssues[];
specAndBodies: Record<string, string>;
streamlinedComments: Record<string, StreamlinedComment[]>;
maxDepth: number;
}

export interface CommentProcessingResult {
processedComments: number;
linkedIssues: LinkedIssues[];
hasCodeReferences: boolean;
}

0 comments on commit ef0b815

Please sign in to comment.