Skip to content

Commit c283b59

Browse files
author
Kilo Code
committed
refactor(git): improve GitExtensionService for better testability
1 parent a621840 commit c283b59

File tree

1 file changed

+31
-8
lines changed

1 file changed

+31
-8
lines changed

src/services/commit-message/GitExtensionService.ts

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ export class GitExtensionService {
7979
const gitExtension = vscode.extensions.getExtension("vscode.git")
8080
if (gitExtension && gitExtension.isActive) {
8181
const gitApi = gitExtension.exports.getAPI(1)
82-
if (gitApi && gitApi.repositories && gitApi.repositories.length > 0) {
82+
if (gitApi?.repositories?.length > 0) {
8383
const repo = gitApi.repositories[0]
8484
repo.inputBox.value = message
85-
vscode.window.showInformationMessage("✨ Commit message set in Git input box!")
8685
return
8786
}
8887
}
@@ -112,27 +111,51 @@ export class GitExtensionService {
112111
}
113112
}
114113

115-
public getStagedDiff(): string {
114+
/**
115+
* Gets the diff of staged changes
116+
* @private Internal helper method
117+
*/
118+
private getStagedDiff(): string {
116119
return this.executeGitCommand("git diff --staged")
117120
}
118121

119-
public getStagedStatus(): string {
122+
/**
123+
* Gets the status of staged files in porcelain format
124+
* @private Internal helper method
125+
*/
126+
private getStagedStatus(): string {
120127
return this.executeGitCommand("git status --porcelain")
121128
}
122129

123-
public getStagedSummary(): string {
130+
/**
131+
* Gets a summary of staged changes
132+
* @private Internal helper method
133+
*/
134+
private getStagedSummary(): string {
124135
return this.executeGitCommand("git diff --staged --stat")
125136
}
126137

127-
public getExtendedDiff(): string {
138+
/**
139+
* Gets extended context for complex changes
140+
* @private Internal helper method
141+
*/
142+
private getExtendedDiff(): string {
128143
return this.executeGitCommand("git diff --staged --unified=5")
129144
}
130145

131-
public getCurrentBranch(): string {
146+
/**
147+
* Gets the current branch name
148+
* @private Internal helper method
149+
*/
150+
private getCurrentBranch(): string {
132151
return this.executeGitCommand("git branch --show-current")
133152
}
134153

135-
public getRecentCommits(count: number = 5): string {
154+
/**
155+
* Gets recent commits for context
156+
* @private Internal helper method
157+
*/
158+
private getRecentCommits(count: number = 5): string {
136159
return this.executeGitCommand(`git log --oneline -${count}`)
137160
}
138161

0 commit comments

Comments
 (0)