Skip to content

Commit 3dbd6d7

Browse files
committed
Replace redundant parsePullRequestList call with lightweight pullRequestSummaryToInfo conversion
In findOpenPr, pullRequests is already ReadonlyArray<GitHubPullRequestSummary> (validated and normalized by GitHubCli.listOpenPullRequests). Passing these through parsePullRequestList — which is designed for raw unknown JSON — was redundant. Add a dedicated pullRequestSummaryToInfo function that directly maps GitHubPullRequestSummary to PullRequestInfo without re-checking types.
1 parent 7b669d8 commit 3dbd6d7

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

apps/server/src/git/Layers/GitManager.ts

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
type GitRunStackedActionOptions,
2323
} from "../Services/GitManager.ts";
2424
import { GitCore } from "../Services/GitCore.ts";
25-
import { GitHubCli } from "../Services/GitHubCli.ts";
25+
import { GitHubCli, type GitHubPullRequestSummary } from "../Services/GitHubCli.ts";
2626
import { TextGeneration } from "../Services/TextGeneration.ts";
2727
import { extractBranchNameFromRemoteRef } from "../remoteRefs.ts";
2828
import { ServerSettingsService } from "../../serverSettings.ts";
@@ -305,6 +305,25 @@ function parsePullRequestList(raw: unknown): PullRequestInfo[] {
305305
return parsed;
306306
}
307307

308+
function pullRequestSummaryToInfo(pr: GitHubPullRequestSummary): PullRequestInfo {
309+
return {
310+
number: pr.number,
311+
title: pr.title,
312+
url: pr.url,
313+
baseRefName: pr.baseRefName,
314+
headRefName: pr.headRefName,
315+
state: pr.state ?? "open",
316+
updatedAt: null,
317+
...(pr.isCrossRepository != null ? { isCrossRepository: pr.isCrossRepository } : {}),
318+
...(pr.headRepositoryNameWithOwner
319+
? { headRepositoryNameWithOwner: pr.headRepositoryNameWithOwner }
320+
: {}),
321+
...(pr.headRepositoryOwnerLogin
322+
? { headRepositoryOwnerLogin: pr.headRepositoryOwnerLogin }
323+
: {}),
324+
};
325+
}
326+
308327
function gitManagerError(operation: string, detail: string, cause?: unknown): GitManagerError {
309328
return new GitManagerError({
310329
operation,
@@ -767,21 +786,13 @@ export const makeGitManager = Effect.fn("makeGitManager")(function* () {
767786
headSelector,
768787
limit: 1,
769788
});
770-
const normalizedPullRequests = parsePullRequestList(pullRequests);
789+
const normalizedPullRequests = pullRequests.map(pullRequestSummaryToInfo);
771790

772791
const firstPullRequest = normalizedPullRequests.find((pullRequest) =>
773792
matchesBranchHeadContext(pullRequest, headContext),
774793
);
775794
if (firstPullRequest) {
776-
return {
777-
number: firstPullRequest.number,
778-
title: firstPullRequest.title,
779-
url: firstPullRequest.url,
780-
baseRefName: firstPullRequest.baseRefName,
781-
headRefName: firstPullRequest.headRefName,
782-
state: "open",
783-
updatedAt: null,
784-
} satisfies PullRequestInfo;
795+
return firstPullRequest;
785796
}
786797
}
787798

0 commit comments

Comments
 (0)