From a5221c79e376b68085a706a85b8abe3c50756eb9 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Thu, 31 Oct 2024 23:58:59 +0000 Subject: [PATCH] chore: type null, filter null --- src/helpers/format-chat-history.ts | 2 +- src/helpers/issue-fetching.ts | 15 +++++++++------ src/types/github-types.ts | 16 +++------------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/helpers/format-chat-history.ts b/src/helpers/format-chat-history.ts index dc38288..bad5d7f 100644 --- a/src/helpers/format-chat-history.ts +++ b/src/helpers/format-chat-history.ts @@ -182,7 +182,7 @@ function createSpecOrBody(specOrBody: string) { function createComment(comment: StreamlinedComments, specOrBody: string) { if (!comment.comments) { - return ""; + return null; } const seen = new Set(); diff --git a/src/helpers/issue-fetching.ts b/src/helpers/issue-fetching.ts index 45e049f..3c8d73a 100644 --- a/src/helpers/issue-fetching.ts +++ b/src/helpers/issue-fetching.ts @@ -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"; @@ -23,8 +23,8 @@ 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() }; } @@ -32,14 +32,17 @@ export async function fetchLinkedIssues(params: FetchParams) { 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 = {}; const seen = new Set([issueKey]); comments.push({ - body: issue.body || "", + body: issue.body, user: issue.user, id: issue.id.toString(), org: params.owner, @@ -250,4 +253,4 @@ function castCommentsToSimplifiedComments(comments: (IssueComments | ReviewComme throw logger.error("Comment type not recognized", { comment, params }); }); -} \ No newline at end of file +} diff --git a/src/types/github-types.ts b/src/types/github-types.ts index 2830da7..590f5d6 100644 --- a/src/types/github-types.ts +++ b/src/types/github-types.ts @@ -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 | null; - body: string | undefined; + body: string | undefined | null; id: string; org: string; repo: string; @@ -47,14 +47,4 @@ export type FetchedPulls = { state: string; merged: boolean; url: string; -}; - -export type LinkedPullsToIssue = { - repository: { - issue: { - closedByPullRequestsReferences: { - nodes: FetchedPulls[]; - }; - }; - }; -}; +}; \ No newline at end of file