Skip to content

Commit ec65aa7

Browse files
committed
fmt
1 parent 21e8b6d commit ec65aa7

7 files changed

Lines changed: 50 additions & 63 deletions

File tree

cmd/cli/llmSetup.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import (
99
"github.com/manifoldco/promptui"
1010
)
1111

12-
13-
1412
// SetupLLM walks the user through selecting an LLM provider and storing the
1513
// corresponding API key or endpoint configuration.
1614
func SetupLLM(Store *store.StoreMethods) error {

cmd/cli/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
var Store *store.StoreMethods
1212

1313
//Initailize store
14-
func StoreInit(sm *store.StoreMethods){
14+
func StoreInit(sm *store.StoreMethods) {
1515
Store = sm
1616
}
1717

@@ -92,7 +92,7 @@ func init() {
9292

9393
// Cobra also supports local flags, which will only run
9494
// when this action is called directly.
95-
95+
9696
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
9797

9898
// Add --dry-run and --auto as persistent flags so they show in top-level help

cmd/cli/store/store.go

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,33 @@ import (
1414
StoreUtils "github.com/dfanso/commit-msg/utils"
1515
)
1616

17-
18-
1917
type StoreMethods struct {
2018
ring keyring.Keyring
2119
}
2220

2321
//Initializes Keyring instance
24-
func KeyringInit() (*StoreMethods, error){
22+
func KeyringInit() (*StoreMethods, error) {
2523
ring, err := keyring.Open(keyring.Config{
2624
ServiceName: "commit-msg",
2725
})
2826
if err != nil {
2927
return nil, fmt.Errorf("failed to open keyring: %w", err)
3028
}
31-
return &StoreMethods{ring:ring},nil
32-
}
33-
29+
return &StoreMethods{ring: ring}, nil
30+
}
3431

3532
// LLMProvider represents a single stored LLM provider and its credential.
3633
type LLMProvider struct {
3734
LLM types.LLMProvider `json:"model"`
3835
APIKey string `json:"api_key"`
3936
}
4037

41-
4238
// Config describes the on-disk structure for all saved LLM providers.
4339
type Config struct {
44-
Default types.LLMProvider `json:"default"`
45-
LLMProviders []types.LLMProvider `json:"models"`
40+
Default types.LLMProvider `json:"default"`
41+
LLMProviders []types.LLMProvider `json:"models"`
4642
}
4743

48-
4944
// Save persists or updates an LLM provider entry, marking it as the default.
5045
func (s *StoreMethods) Save(LLMConfig LLMProvider) error {
5146

@@ -78,13 +73,12 @@ func (s *StoreMethods) Save(LLMConfig LLMProvider) error {
7873
}
7974
}
8075

81-
8276
// If Model already present in config, update the apiKey
8377
updated := false
8478
for _, p := range cfg.LLMProviders {
8579
if p == LLMConfig.LLM {
8680
err := s.ring.Set(keyring.Item{ //save apiKey using keychain to OS credentials
87-
Key: string(LLMConfig.LLM),
81+
Key: string(LLMConfig.LLM),
8882
Data: []byte(LLMConfig.APIKey),
8983
})
9084
if err != nil {
@@ -98,13 +92,13 @@ func (s *StoreMethods) Save(LLMConfig LLMProvider) error {
9892
// If fresh Model is saved, means model not exists in config file
9993
if !updated {
10094
cfg.LLMProviders = append(cfg.LLMProviders, LLMConfig.LLM)
101-
err := s.ring.Set(keyring.Item{ //save apiKey using keychain to OS credentials
102-
Key: string(LLMConfig.LLM),
103-
Data: []byte(LLMConfig.APIKey),
104-
})
95+
err := s.ring.Set(keyring.Item{ //save apiKey using keychain to OS credentials
96+
Key: string(LLMConfig.LLM),
97+
Data: []byte(LLMConfig.APIKey),
98+
})
10599
if err != nil {
106-
return errors.New("error storing credentials")
107-
}
100+
return errors.New("error storing credentials")
101+
}
108102
}
109103

110104
cfg.Default = LLMConfig.LLM
@@ -117,11 +111,9 @@ func (s *StoreMethods) Save(LLMConfig LLMProvider) error {
117111
return os.WriteFile(configPath, data, 0600)
118112
}
119113

120-
121114
// DefaultLLMKey returns the currently selected default LLM provider, if any.
122115
func (s *StoreMethods) DefaultLLMKey() (*LLMProvider, error) {
123116

124-
125117
var cfg Config
126118
var useModel LLMProvider
127119

@@ -153,10 +145,10 @@ func (s *StoreMethods) DefaultLLMKey() (*LLMProvider, error) {
153145

154146
for i, p := range cfg.LLMProviders {
155147
if p == defaultLLM {
156-
useModel.LLM = cfg.LLMProviders[i] // Fetches default Model from config json
157-
i,err := s.ring.Get(string(useModel.LLM)) //Fetches apiKey from OS credential for default model
148+
useModel.LLM = cfg.LLMProviders[i] // Fetches default Model from config json
149+
i, err := s.ring.Get(string(useModel.LLM)) //Fetches apiKey from OS credential for default model
158150
if err != nil {
159-
return nil,err
151+
return nil, err
160152
}
161153
useModel.APIKey = string(i.Data)
162154
return &useModel, nil
@@ -280,8 +272,8 @@ func (s *StoreMethods) DeleteModel(Model types.LLMProvider) error {
280272
} else {
281273
err := s.ring.Remove(string(Model)) // Removes the apiKey from OS credentials
282274
if err != nil {
283-
return err
284-
}
275+
return err
276+
}
285277
return os.WriteFile(configPath, []byte("{}"), 0600)
286278
}
287279
} else {
@@ -292,7 +284,7 @@ func (s *StoreMethods) DeleteModel(Model types.LLMProvider) error {
292284
newCfg.LLMProviders = append(newCfg.LLMProviders, p)
293285
}
294286
}
295-
287+
296288
err := s.ring.Remove(string(Model)) //Remove the apiKey from OS credentials
297289
if err != nil {
298290
return err
@@ -338,8 +330,8 @@ func (s *StoreMethods) UpdateAPIKey(Model types.LLMProvider, APIKey string) erro
338330
updated := false
339331
for _, p := range cfg.LLMProviders {
340332
if p == Model {
341-
err := s.ring.Set(keyring.Item{ // Update the apiKey in OS credential
342-
Key: string(Model),
333+
err := s.ring.Set(keyring.Item{ // Update the apiKey in OS credential
334+
Key: string(Model),
343335
Data: []byte(APIKey),
344336
})
345337
if err != nil {
@@ -361,4 +353,3 @@ func (s *StoreMethods) UpdateAPIKey(Model types.LLMProvider, APIKey string) erro
361353
return os.WriteFile(configPath, data, 0600)
362354

363355
}
364-

cmd/commit-msg/main.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import (
99

1010
// main is the entry point of the commit message generator
1111
func main() {
12-
12+
1313
//Initializes the OS credential manager
1414
KeyRing, err := store.KeyringInit()
15-
if err != nil {
16-
log.Fatalf("Failed to initilize Keyring store: %v", err)
17-
}
15+
if err != nil {
16+
log.Fatalf("Failed to initilize Keyring store: %v", err)
17+
}
1818
cmd.StoreInit(KeyRing) //Passes StoreMethods instance to root
1919
cmd.Execute()
20-
}
21-
22-
20+
}

internal/git/operations.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ func parseGitNameStatus(line string) parseGitStatusLine {
3434
if line == "" {
3535
return parseGitStatusLine{}
3636
}
37-
37+
3838
// Git uses tabs to separate fields in --name-status output
3939
parts := strings.Split(line, "\t")
4040
if len(parts) < 2 {
4141
return parseGitStatusLine{}
4242
}
43-
43+
4444
status := parts[0]
45-
45+
4646
// Handle rename/copy status codes (e.g., "R100", "C75")
4747
if len(status) > 1 && (status[0] == 'R' || status[0] == 'C') {
4848
// For rename/copy, we expect: "R100\toldname\tnewname" or "C75\toldname\tnewname"
@@ -56,7 +56,7 @@ func parseGitNameStatus(line string) parseGitStatusLine {
5656
}
5757
}
5858
}
59-
59+
6060
// Handle regular status codes (M, A, D, etc.)
6161
filename := parts[1]
6262
return parseGitStatusLine{
@@ -70,21 +70,21 @@ func processGitStatusOutput(nameStatusOutput string, returnFilenames bool) ([]st
7070
if nameStatusOutput == "" {
7171
return nil, nil
7272
}
73-
73+
7474
lines := strings.Split(strings.TrimSpace(nameStatusOutput), "\n")
7575
var filteredLines []string
7676
var nonBinaryFiles []string
77-
77+
7878
for _, line := range lines {
7979
if line == "" {
8080
continue
8181
}
82-
82+
8383
parsed := parseGitNameStatus(line)
8484
if len(parsed.filenames) == 0 {
8585
continue
8686
}
87-
87+
8888
// Check if any of the filenames are binary
8989
hasBinaryFile := false
9090
for _, filename := range parsed.filenames {
@@ -93,7 +93,7 @@ func processGitStatusOutput(nameStatusOutput string, returnFilenames bool) ([]st
9393
break
9494
}
9595
}
96-
96+
9797
// If no binary files found, include this line/files
9898
if !hasBinaryFile {
9999
filteredLines = append(filteredLines, line)
@@ -102,18 +102,18 @@ func processGitStatusOutput(nameStatusOutput string, returnFilenames bool) ([]st
102102
}
103103
}
104104
}
105-
105+
106106
return filteredLines, nonBinaryFiles
107107
}
108108

109109
// filterBinaryFiles filters out binary files from git diff --name-status output
110110
func filterBinaryFiles(nameStatusOutput string) string {
111111
filteredLines, _ := processGitStatusOutput(nameStatusOutput, false)
112-
112+
113113
if len(filteredLines) == 0 {
114114
return ""
115115
}
116-
116+
117117
return strings.Join(filteredLines, "\n")
118118
}
119119

@@ -137,7 +137,7 @@ func GetChanges(config *types.RepoConfig) (string, error) {
137137
if len(output) > 0 {
138138
// Filter out binary files from the name-status output
139139
filteredOutput := filterBinaryFiles(string(output))
140-
140+
141141
if filteredOutput != "" {
142142
changes.WriteString("Unstaged changes:\n")
143143
changes.WriteString(filteredOutput)
@@ -170,7 +170,7 @@ func GetChanges(config *types.RepoConfig) (string, error) {
170170
if len(stagedOutput) > 0 {
171171
// Filter out binary files from the staged changes
172172
filteredStagedOutput := filterBinaryFiles(string(stagedOutput))
173-
173+
174174
if filteredStagedOutput != "" {
175175
changes.WriteString("Staged changes:\n")
176176
changes.WriteString(filteredStagedOutput)
@@ -204,7 +204,7 @@ func GetChanges(config *types.RepoConfig) (string, error) {
204204
// Filter out binary files from untracked files
205205
untrackedFiles := strings.Split(strings.TrimSpace(string(untrackedOutput)), "\n")
206206
var nonBinaryUntrackedFiles []string
207-
207+
208208
for _, file := range untrackedFiles {
209209
if file == "" {
210210
continue
@@ -213,7 +213,7 @@ func GetChanges(config *types.RepoConfig) (string, error) {
213213
nonBinaryUntrackedFiles = append(nonBinaryUntrackedFiles, file)
214214
}
215215
}
216-
216+
217217
if len(nonBinaryUntrackedFiles) > 0 {
218218
changes.WriteString("Untracked files:\n")
219219
changes.WriteString(strings.Join(nonBinaryUntrackedFiles, "\n"))

internal/http/client.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88
)
99

1010
var (
11-
clientOnce sync.Once
11+
clientOnce sync.Once
1212
sharedClient *http.Client
13-
13+
1414
ollamaClientOnce sync.Once
15-
ollamaClient *http.Client
15+
ollamaClient *http.Client
1616
)
1717

1818
// createTransport creates a shared HTTP transport with optimized settings
@@ -48,4 +48,4 @@ func GetOllamaClient() *http.Client {
4848
}
4949
})
5050
return ollamaClient
51-
}
51+
}

internal/utils/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func IsTextFile(filename string) bool {
2222
".txt", ".md", ".go", ".js", ".py", ".java", ".c", ".cpp", ".h",
2323
".html", ".css", ".json", ".xml", ".yaml", ".yml", ".sh", ".bash",
2424
".ts", ".tsx", ".jsx", ".php", ".rb", ".rs", ".dart", ".sql", ".r",
25-
".scala", ".kt", ".swift", ".m", ".pl", ".lua", ".vim", ".csv",
25+
".scala", ".kt", ".swift", ".m", ".pl", ".lua", ".vim", ".csv",
2626
".log", ".cfg", ".conf", ".ini", ".toml", ".lock", ".gitignore",
2727
".dockerfile", ".makefile", ".cmake", ".pro", ".pri", ".svg",
2828
}
@@ -38,11 +38,11 @@ func IsTextFile(filename string) bool {
3838
if ext == "" {
3939
baseName := strings.ToLower(filepath.Base(filename))
4040
commonTextFiles := []string{
41-
"readme", "dockerfile", "makefile", "rakefile", "gemfile",
41+
"readme", "dockerfile", "makefile", "rakefile", "gemfile",
4242
"procfile", "jenkinsfile", "vagrantfile", "changelog", "authors",
4343
"contributors", "copying", "install", "news", "todo",
4444
}
45-
45+
4646
for _, textFile := range commonTextFiles {
4747
if baseName == textFile {
4848
return true

0 commit comments

Comments
 (0)