Skip to content

Commit 8951f63

Browse files
say8425claude
andcommitted
refactor: simplify git stats extraction with map/reduce
- Refactor repeated regex extraction logic using array map - Fix biome formatting (break long line) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 461a8eb commit 8951f63

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

src/index.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,15 @@ async function getGitChangesCached(): Promise<{
107107
const combined = `${diff}\n${staged}`;
108108

109109
// 파일 수, insertions, deletions 추출
110-
const files = (combined.match(/(\d+) file/g) || []).reduce(
111-
(sum, m) => sum + Number.parseInt(m, 10),
112-
0,
113-
);
114-
const insertions = (combined.match(/(\d+) insertion/g) || []).reduce(
115-
(sum, m) => sum + Number.parseInt(m, 10),
116-
0,
117-
);
118-
const deletions = (combined.match(/(\d+) deletion/g) || []).reduce(
119-
(sum, m) => sum + Number.parseInt(m, 10),
120-
0,
110+
const [files, insertions, deletions] = [
111+
/(\d+) file/g,
112+
/(\d+) insertion/g,
113+
/(\d+) deletion/g,
114+
].map((regex) =>
115+
(combined.match(regex) || []).reduce(
116+
(sum, m) => sum + Number.parseInt(m, 10),
117+
0,
118+
),
121119
);
122120
cache.gitChanges = { files, insertions, deletions, timestamp: Date.now() };
123121
return cache.gitChanges;
@@ -194,7 +192,10 @@ async function main() {
194192
);
195193

196194
// 3번째 줄: git changes | PR URL
197-
const hasGitChanges = gitChanges.files > 0 || gitChanges.insertions > 0 || gitChanges.deletions > 0;
195+
const hasGitChanges =
196+
gitChanges.files > 0 ||
197+
gitChanges.insertions > 0 ||
198+
gitChanges.deletions > 0;
198199
if (hasGitChanges || prUrl) {
199200
let line3 = "";
200201
if (hasGitChanges) {

0 commit comments

Comments
 (0)