Skip to content

Commit

Permalink
chore: type null, filter null
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Oct 31, 2024
1 parent a6ffb03 commit a5221c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/helpers/format-chat-history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ function createSpecOrBody(specOrBody: string) {

function createComment(comment: StreamlinedComments, specOrBody: string) {
if (!comment.comments) {
return "";
return null;
}

const seen = new Set<number>();
Expand Down
15 changes: 9 additions & 6 deletions src/helpers/issue-fetching.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createKey, getAllStreamlinedComments } from "../handlers/comments";
import { Context } from "../types";
import { IssueComments, FetchParams, Issue, LinkedIssues, LinkedPullsToIssue, ReviewComments, SimplifiedComment } from "../types/github-types";
import { IssueComments, FetchParams, Issue, LinkedIssues, ReviewComments, SimplifiedComment } from "../types/github-types";
import { StreamlinedComment, TokenLimits } from "../types/llm";
import { logger } from "./errors";
import { dedupeStreamlinedComments, fetchCodeLinkedFromIssue, idIssueFromComment, mergeStreamlinedComments, splitKey } from "./issue";
Expand All @@ -23,23 +23,26 @@ export async function recursivelyFetchLinkedIssues(params: FetchParams) {
}

export async function fetchLinkedIssues(params: FetchParams) {
const { comments, issue } = await fetchIssueComments(params);
if (!issue) {
const fetchedIssueAndComments = await fetchIssueComments(params);
if (!fetchedIssueAndComments.issue) {
return { streamlinedComments: {}, linkedIssues: [], specAndBodies: {}, seen: new Set<string>() };
}

if (!params.owner || !params.repo) {
throw logger.error("Owner or repo not found");
}

const issue = fetchedIssueAndComments.issue;
const comments = fetchedIssueAndComments.comments.filter((comment) => comment.body !== undefined);

const issueKey = createKey(issue.html_url);
const [owner, repo, issueNumber] = splitKey(issueKey);
const linkedIssues: LinkedIssues[] = [{ body: issue.body || "", comments, issueNumber: parseInt(issueNumber), owner, repo, url: issue.html_url }];
const linkedIssues: LinkedIssues[] = [{ body: issue.body, comments, issueNumber: parseInt(issueNumber), owner, repo, url: issue.html_url }];
const specAndBodies: Record<string, string> = {};
const seen = new Set<string>([issueKey]);

comments.push({
body: issue.body || "",
body: issue.body,
user: issue.user,
id: issue.id.toString(),
org: params.owner,
Expand Down Expand Up @@ -250,4 +253,4 @@ function castCommentsToSimplifiedComments(comments: (IssueComments | ReviewComme

throw logger.error("Comment type not recognized", { comment, params });
});
}
}
16 changes: 3 additions & 13 deletions src/types/github-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ export type LinkedIssues = {
owner: string;
url: string;
comments?: SimplifiedComment[] | null | undefined;
body: string | undefined;
body: string | undefined | null;
};

export type SimplifiedComment = {
user: Partial<User> | null;
body: string | undefined;
body: string | undefined | null;
id: string;
org: string;
repo: string;
Expand All @@ -47,14 +47,4 @@ export type FetchedPulls = {
state: string;
merged: boolean;
url: string;
};

export type LinkedPullsToIssue = {
repository: {
issue: {
closedByPullRequestsReferences: {
nodes: FetchedPulls[];
};
};
};
};
};

0 comments on commit a5221c7

Please sign in to comment.