Skip to content

Commit 4312053

Browse files
refactor(cli): extract findGitRoot to dedicated git utility file
Move findGitRoot function from logger.ts to new git.ts utility file for better code organization. Update imports in logger.ts and codebuff-client.ts accordingly. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent c710a2d commit 4312053

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

cli/src/utils/codebuff-client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CodebuffClient } from '@codebuff/sdk'
22

3+
import { findGitRoot } from './git'
34
import { logger } from './logger'
45

56
let clientInstance: CodebuffClient | null = null
@@ -14,11 +15,12 @@ export function getCodebuffClient(): CodebuffClient | null {
1415
return null
1516
}
1617

17-
logger.info('Initializing CodebuffClient with API key')
18+
const gitRoot = findGitRoot()
19+
logger.info('Initializing CodebuffClient with API key', { cwd: gitRoot })
1820
try {
1921
clientInstance = new CodebuffClient({
2022
apiKey,
21-
cwd: process.cwd(),
23+
cwd: gitRoot,
2224
})
2325
logger.info('CodebuffClient initialized successfully')
2426
} catch (error) {

cli/src/utils/git.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { dirname, join } from 'path'
2+
import { existsSync } from 'fs'
3+
4+
export function findGitRoot(): string {
5+
let currentDir = process.cwd()
6+
7+
while (currentDir !== dirname(currentDir)) {
8+
if (existsSync(join(currentDir, '.git'))) {
9+
return currentDir
10+
}
11+
currentDir = dirname(currentDir)
12+
}
13+
14+
return process.cwd()
15+
}

cli/src/utils/logger.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
import { appendFileSync, existsSync, mkdirSync, unlinkSync } from 'fs'
2-
import { join, dirname } from 'path'
2+
import { join } from 'path'
33

4-
function findGitRoot(): string {
5-
let currentDir = process.cwd()
6-
7-
while (currentDir !== dirname(currentDir)) {
8-
if (existsSync(join(currentDir, '.git'))) {
9-
return currentDir
10-
}
11-
currentDir = dirname(currentDir)
12-
}
13-
14-
return process.cwd()
15-
}
4+
import { findGitRoot } from './git'
165

176
const PROJECT_ROOT = findGitRoot()
187
const LOG_DIR = join(PROJECT_ROOT, 'debug')

0 commit comments

Comments
 (0)