Skip to content

Commit a83fbcc

Browse files
author
“chae-dahee”
committed
refactor: perPage → commitCountPerPage
1 parent 39b4105 commit a83fbcc

10 files changed

Lines changed: 39 additions & 75 deletions

File tree

packages/analysis-engine/src/csm.spec.ts

Lines changed: 13 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,8 @@ describe("csm", () => {
438438

439439
describe("buildPaginatedCSMDict", () => {
440440
it("should load first page when lastCommitId is not provided", () => {
441-
const perPage = 2;
442-
const result = buildPaginatedCSMDict(
443-
fakeCommitNodeDict,
444-
fakeStemDict,
445-
"master",
446-
perPage
447-
);
441+
const commitCountPerPage = 2;
442+
const result = buildPaginatedCSMDict(fakeCommitNodeDict, fakeStemDict, "master", commitCountPerPage);
448443

449444
expect(result).toBeDefined();
450445
expect(result.master).toBeDefined();
@@ -456,12 +451,12 @@ describe("csm", () => {
456451
});
457452

458453
it("should load next page when lastCommitId is provided", () => {
459-
const perPage = 2;
454+
const commitCountPerPage = 2;
460455
const result = buildPaginatedCSMDict(
461456
fakeCommitNodeDict,
462457
fakeStemDict,
463458
"master",
464-
perPage,
459+
commitCountPerPage,
465460
"4" // Last commit of first page
466461
);
467462

@@ -474,12 +469,12 @@ describe("csm", () => {
474469
});
475470

476471
it("should return remaining nodes when perPage exceeds remaining nodes", () => {
477-
const perPage = 10;
472+
const commitCountPerPage = 10;
478473
const result = buildPaginatedCSMDict(
479474
fakeCommitNodeDict,
480475
fakeStemDict,
481476
"master",
482-
perPage,
477+
commitCountPerPage,
483478
"2" // Only [1, 0] remaining
484479
);
485480

@@ -491,12 +486,12 @@ describe("csm", () => {
491486
});
492487

493488
it("should return empty array when no more nodes available", () => {
494-
const perPage = 2;
489+
const commitCountPerPage = 2;
495490
const result = buildPaginatedCSMDict(
496491
fakeCommitNodeDict,
497492
fakeStemDict,
498493
"master",
499-
perPage,
494+
commitCountPerPage,
500495
"0" // Last node
501496
);
502497

@@ -507,44 +502,23 @@ describe("csm", () => {
507502

508503
it("should throw error when lastCommitId is invalid", () => {
509504
expect(() => {
510-
buildPaginatedCSMDict(
511-
fakeCommitNodeDict,
512-
fakeStemDict,
513-
"master",
514-
2,
515-
"invalid-commit-id"
516-
);
505+
buildPaginatedCSMDict(fakeCommitNodeDict, fakeStemDict, "master", 2, "invalid-commit-id");
517506
}).toThrow("Invalid lastCommitId");
518507
});
519508

520509
it("should throw error when perPage is less than or equal to 0", () => {
521510
expect(() => {
522-
buildPaginatedCSMDict(
523-
fakeCommitNodeDict,
524-
fakeStemDict,
525-
"master",
526-
0
527-
);
511+
buildPaginatedCSMDict(fakeCommitNodeDict, fakeStemDict, "master", 0);
528512
}).toThrow("perPage must be greater than 0");
529513

530514
expect(() => {
531-
buildPaginatedCSMDict(
532-
fakeCommitNodeDict,
533-
fakeStemDict,
534-
"master",
535-
-1
536-
);
515+
buildPaginatedCSMDict(fakeCommitNodeDict, fakeStemDict, "master", -1);
537516
}).toThrow("perPage must be greater than 0");
538517
});
539518

540519
it("should throw error when base branch does not exist", () => {
541520
expect(() => {
542-
buildPaginatedCSMDict(
543-
fakeCommitNodeDict,
544-
fakeStemDict,
545-
"non-existent-branch",
546-
2
547-
);
521+
buildPaginatedCSMDict(fakeCommitNodeDict, fakeStemDict, "non-existent-branch", 2);
548522
}).toThrow("no master-stem");
549523
});
550524

@@ -566,14 +540,7 @@ describe("csm", () => {
566540
},
567541
} as unknown as PullRequest;
568542

569-
const result = buildPaginatedCSMDict(
570-
fakeCommitNodeDict,
571-
fakeStemDict,
572-
"master",
573-
1,
574-
undefined,
575-
[fakePR]
576-
);
543+
const result = buildPaginatedCSMDict(fakeCommitNodeDict, fakeStemDict, "master", 1, undefined, [fakePR]);
577544

578545
expect(result.master[0].base.commit.id).toBe("5");
579546
// PR integration logic should be applied

packages/analysis-engine/src/csm.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ export const buildPaginatedCSMDict = (
165165
commitDict: CommitDict,
166166
stemDict: StemDict,
167167
baseBranchName: string,
168-
perPage: number,
168+
commitCountPerPage: number,
169169
lastCommitId?: string,
170170
pullRequests: Array<PullRequest> = []
171171
): CSMDictionary => {
172-
// Validate perPage
173-
if (perPage <= 0) {
174-
throw new Error("perPage must be greater than 0");
172+
// Validate commitCountPerPage
173+
if (commitCountPerPage <= 0) {
174+
throw new Error("commitCountPerPage must be greater than 0");
175175
}
176176

177177
// Validate stemDict
@@ -196,7 +196,7 @@ export const buildPaginatedCSMDict = (
196196
}
197197

198198
// Calculate end index and extract page nodes
199-
const endIndex = Math.min(startIndex + perPage, baseStem.nodes.length);
199+
const endIndex = Math.min(startIndex + commitCountPerPage, baseStem.nodes.length);
200200
const pageNodes = baseStem.nodes.slice(startIndex, endIndex);
201201

202202
// Build CSM nodes with PR integration

packages/analysis-engine/src/index.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,25 @@ export class AnalysisEngine {
8383
if (this.isDebugMode) console.log("stemDict: ", this.stemDict);
8484
};
8585

86-
public analyzeGit = async (
87-
perPage?: number,
88-
lastCommitId?: string
89-
): Promise<AnalyzeGitResult> => {
86+
public analyzeGit = async (commitCountPerPage?: number, lastCommitId?: string): Promise<AnalyzeGitResult> => {
9087
if (!this.commitDict || !this.stemDict || !this.pullRequests) {
9188
throw new Error("AnalysisEngine not initialized. Call init() first.");
9289
}
9390

9491
// Paginated CSM
95-
if (perPage) {
92+
if (commitCountPerPage) {
9693
const csmDict = buildPaginatedCSMDict(
9794
this.commitDict,
9895
this.stemDict,
9996
this.baseBranchName,
100-
perPage,
97+
commitCountPerPage,
10198
lastCommitId,
10299
this.pullRequests
103100
);
104101
const list = csmDict[this.baseBranchName] ?? [];
105102
const lastNode = list.length > 0 ? list[list.length - 1] : undefined;
106103

107-
const isLastPage = list.length < perPage;
104+
const isLastPage = list.length < commitCountPerPage;
108105
const nextCommitId = !isLastPage && lastNode ? lastNode.base.commit.id : undefined;
109106

110107
return {

packages/view/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { RefreshButton } from "components/RefreshButton";
1212
import type { IDESentEvents } from "types/IDESentEvents";
1313
import { useBranchStore, useDataStore, useGithubInfo, useLoadingStore, useThemeStore } from "store";
1414
import { THEME_INFO } from "components/ThemeSelector/ThemeSelector.const";
15-
import { PER_PAGE } from "constants/constants";
15+
import { COMMIT_COUNT_PER_PAGE } from "constants/constants";
1616

1717
const App = () => {
1818
const initRef = useRef<boolean>(false);
@@ -38,7 +38,7 @@ const App = () => {
3838
};
3939
setLoading(true);
4040
ideAdapter.addIDESentEventListener(callbacks);
41-
ideAdapter.sendFetchAnalyzedDataMessage({ perPage: PER_PAGE });
41+
ideAdapter.sendFetchAnalyzedDataMessage({ commitCountPerPage: COMMIT_COUNT_PER_PAGE });
4242
ideAdapter.sendFetchBranchListMessage();
4343
ideAdapter.sendFetchGithubInfo();
4444
initRef.current = true;
@@ -50,7 +50,7 @@ const App = () => {
5050

5151
setLoading(true);
5252
ideAdapter.sendFetchAnalyzedDataMessage({
53-
perPage: PER_PAGE,
53+
commitCountPerPage: COMMIT_COUNT_PER_PAGE,
5454
lastCommitId: nextCommitId,
5555
});
5656
};

packages/view/src/components/BranchSelector/BranchSelector.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import "./BranchSelector.scss";
88
import { useBranchStore, useLoadingStore } from "store";
99

1010
import { SLICE_LENGTH } from "./BranchSelector.const";
11-
import { PER_PAGE } from "constants/constants";
11+
import { COMMIT_COUNT_PER_PAGE } from "constants/constants";
1212

1313
const BranchSelector = () => {
1414
const { branchList, selectedBranch, setSelectedBranch } = useBranchStore();
@@ -17,7 +17,7 @@ const BranchSelector = () => {
1717
const handleChangeSelect = (event: SelectChangeEvent) => {
1818
setSelectedBranch(event.target.value);
1919
setLoading(true);
20-
sendFetchAnalyzedDataCommand({ baseBranch: event.target.value, perPage: PER_PAGE });
20+
sendFetchAnalyzedDataCommand({ baseBranch: event.target.value, commitCountPerPage: COMMIT_COUNT_PER_PAGE });
2121
};
2222

2323
return (

packages/view/src/components/RefreshButton/RefreshButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ import { throttle } from "utils";
77
import "./RefreshButton.scss";
88
import { sendRefreshDataCommand } from "services";
99
import { useBranchStore, useLoadingStore } from "store";
10-
import { PER_PAGE } from "constants/constants";
10+
import { COMMIT_COUNT_PER_PAGE } from "constants/constants";
1111

1212
const RefreshButton = () => {
1313
const { selectedBranch } = useBranchStore();
1414
const { loading, setLoading } = useLoadingStore();
1515

1616
const refreshHandler = throttle(() => {
1717
setLoading(true);
18-
sendRefreshDataCommand({ selectedBranch, perPage: PER_PAGE });
18+
sendRefreshDataCommand({ selectedBranch, commitCountPerPage: COMMIT_COUNT_PER_PAGE });
1919
}, 3000);
2020

2121
return (

packages/view/src/constants/constants.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ export const GITHUB_URL = "https://github.com";
22
export const GRAVATA_URL = "https://www.gravatar.com/avatar";
33
export const PRIMARY_COLOR_VARIABLE_NAME = "--color-primary";
44
export const NODE_TYPES = ["COMMIT", "CLUSTER"] as const;
5-
export const PER_PAGE = 10;
5+
export const COMMIT_COUNT_PER_PAGE = 10;

packages/view/src/types/IDEMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export type IDEMessageCommandNames =
1717

1818
export type RefreshDataRequestPayload = {
1919
selectedBranch?: string;
20-
perPage?: number;
20+
commitCountPerPage?: number;
2121
lastCommitId?: string;
2222
};
2323

2424
export type FetchDataRequestPayload = {
2525
baseBranch?: string;
26-
perPage?: number;
26+
commitCountPerPage?: number;
2727
lastCommitId?: string;
2828
};

packages/vscode/src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export async function activate(context: vscode.ExtensionContext) {
7979

8080
const fetchClusterNodes = async (
8181
baseBranchName = initialBaseBranchName,
82-
perPage?: number,
82+
commitCountPerPage?: number,
8383
lastCommitId?: string,
8484
command?: string
8585
): Promise<ClusterNodesResult> => {
@@ -103,7 +103,7 @@ export async function activate(context: vscode.ExtensionContext) {
103103
throw new Error("Analysis engine is not initialized.");
104104
}
105105

106-
const analysisResult = await engine.analyzeGit(perPage, lastCommitId);
106+
const analysisResult = await engine.analyzeGit(commitCountPerPage, lastCommitId);
107107

108108
if (analysisResult.isPRSuccess) console.log("crawling PR Success");
109109

packages/vscode/src/webview-loader.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from "path";
22
import * as vscode from "vscode";
33

44
import { getTheme, setTheme } from "./setting-repository";
5-
import type { ClusterNode, ClusterNodesResult } from "./types/Node";
5+
import type { ClusterNodesResult } from "./types/Node";
66

77
const ANALYZE_DATA_KEY = "memento_analyzed_data";
88

@@ -36,10 +36,10 @@ export default class WebviewLoader implements vscode.Disposable {
3636

3737
if (command === "refresh") {
3838
const requestPayload = payload ? JSON.parse(payload) : {};
39-
const { selectedBranch, perPage, lastCommitId } = requestPayload;
39+
const { selectedBranch, commitCountPerPage, lastCommitId } = requestPayload;
4040
const currentBranch = selectedBranch ?? (await fetchCurrentBranch());
4141

42-
const clusterData = await fetchClusterNodes(currentBranch, perPage, lastCommitId, "refresh");
42+
const clusterData = await fetchClusterNodes(currentBranch, commitCountPerPage, lastCommitId, "refresh");
4343
analyzedData = {
4444
...clusterData,
4545
isLoadMore: !!lastCommitId,
@@ -53,7 +53,7 @@ export default class WebviewLoader implements vscode.Disposable {
5353

5454
if (command === "fetchAnalyzedData") {
5555
const requestPayload = payload ? JSON.parse(payload) : {};
56-
const { baseBranch, perPage, lastCommitId } = requestPayload;
56+
const { baseBranch, commitCountPerPage, lastCommitId } = requestPayload;
5757
const currentBranch = baseBranch ?? (await fetchCurrentBranch());
5858

5959
const cacheKey = `${ANALYZE_DATA_KEY}_${currentBranch}_${lastCommitId || "firstPage"}`;
@@ -63,7 +63,7 @@ export default class WebviewLoader implements vscode.Disposable {
6363
if (storedAnalyzedData) {
6464
analyzedData = storedAnalyzedData;
6565
} else {
66-
const clusterData = await fetchClusterNodes(currentBranch, perPage, lastCommitId);
66+
const clusterData = await fetchClusterNodes(currentBranch, commitCountPerPage, lastCommitId);
6767
analyzedData = {
6868
...clusterData,
6969
isLoadMore: !!lastCommitId,

0 commit comments

Comments
 (0)