Skip to content

Commit ec3d2bc

Browse files
committed
Improved Docstring Coverage
1 parent 97470d5 commit ec3d2bc

10 files changed

Lines changed: 41 additions & 0 deletions

File tree

cmd/cli/createMsg.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424
"github.com/pterm/pterm"
2525
)
2626

27+
// CreateCommitMsg launches the interactive flow for reviewing, regenerating,
28+
// editing, and accepting AI-generated commit messages in the current repo.
2729
func CreateCommitMsg() {
2830
// Validate COMMIT_LLM and required API keys
2931
useLLM, err := store.DefaultLLMKey()

cmd/cli/llmSetup.go

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

12+
// SetupLLM walks the user through selecting an LLM provider and storing the
13+
// corresponding API key or endpoint configuration.
1214
func SetupLLM() error {
1315

1416
providers := types.GetSupportedProviderStrings()
@@ -67,6 +69,8 @@ func SetupLLM() error {
6769
return nil
6870
}
6971

72+
// UpdateLLM lets the user switch defaults, rotate API keys, or delete stored
73+
// LLM provider configurations.
7074
func UpdateLLM() error {
7175

7276
SavedModels, err := store.ListSavedModels()

cmd/cli/store/store.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package store persists user-selected LLM providers and credentials.
12
package store
23

34
import (
@@ -11,16 +12,19 @@ import (
1112
"github.com/dfanso/commit-msg/pkg/types"
1213
)
1314

15+
// LLMProvider represents a single stored LLM provider and its credential.
1416
type LLMProvider struct {
1517
LLM types.LLMProvider `json:"model"`
1618
APIKey string `json:"api_key"`
1719
}
1820

21+
// Config describes the on-disk structure for all saved LLM providers.
1922
type Config struct {
2023
Default types.LLMProvider `json:"default"`
2124
LLMProviders []LLMProvider `json:"models"`
2225
}
2326

27+
// Save persists or updates an LLM provider entry, marking it as the default.
2428
func Save(LLMConfig LLMProvider) error {
2529

2630
cfg := Config{
@@ -139,6 +143,7 @@ func getConfigPath() (string, error) {
139143

140144
}
141145

146+
// DefaultLLMKey returns the currently selected default LLM provider, if any.
142147
func DefaultLLMKey() (*LLMProvider, error) {
143148

144149
var cfg Config
@@ -179,6 +184,7 @@ func DefaultLLMKey() (*LLMProvider, error) {
179184
return nil, errors.New("not found default model in config")
180185
}
181186

187+
// ListSavedModels loads all persisted LLM provider configurations.
182188
func ListSavedModels() (*Config, error) {
183189

184190
var cfg Config
@@ -211,6 +217,7 @@ func ListSavedModels() (*Config, error) {
211217

212218
}
213219

220+
// ChangeDefault updates the default LLM provider selection in the config.
214221
func ChangeDefault(Model types.LLMProvider) error {
215222

216223
var cfg Config
@@ -247,6 +254,7 @@ func ChangeDefault(Model types.LLMProvider) error {
247254
return os.WriteFile(configPath, data, 0600)
248255
}
249256

257+
// DeleteModel removes the specified provider from the saved configuration.
250258
func DeleteModel(Model types.LLMProvider) error {
251259

252260
var cfg Config
@@ -300,6 +308,7 @@ func DeleteModel(Model types.LLMProvider) error {
300308
}
301309
}
302310

311+
// UpdateAPIKey rotates the credential for an existing provider entry.
303312
func UpdateAPIKey(Model types.LLMProvider, APIKey string) error {
304313

305314
var cfg Config

internal/chatgpt/chatgpt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/dfanso/commit-msg/pkg/types"
1111
)
1212

13+
// GenerateCommitMessage calls OpenAI's chat completions API to turn the provided
14+
// repository changes into a polished git commit message.
1315
func GenerateCommitMessage(config *types.Config, changes string, apiKey string, opts *types.GenerationOptions) (string, error) {
1416

1517
client := openai.NewClient(option.WithAPIKey(apiKey))

internal/claude/claude.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ import (
1010
"github.com/dfanso/commit-msg/pkg/types"
1111
)
1212

13+
// ClaudeRequest describes the payload sent to Anthropic's Claude messages API.
1314
type ClaudeRequest struct {
1415
Model string `json:"model"`
1516
Messages []Message `json:"messages"`
1617
MaxTokens int `json:"max_tokens"`
1718
}
1819

20+
// Message represents a single role/content pair exchanged with Claude.
1921
type Message struct {
2022
Role string `json:"role"`
2123
Content string `json:"content"`
2224
}
2325

26+
// ClaudeResponse captures the subset of fields used from Anthropic responses.
2427
type ClaudeResponse struct {
2528
ID string `json:"id"`
2629
Type string `json:"type"`
@@ -30,6 +33,7 @@ type ClaudeResponse struct {
3033
} `json:"content"`
3134
}
3235

36+
// GenerateCommitMessage produces a commit summary using Anthropic's Claude API.
3337
func GenerateCommitMessage(config *types.Config, changes string, apiKey string, opts *types.GenerationOptions) (string, error) {
3438

3539
prompt := types.BuildCommitPrompt(changes, opts)

internal/gemini/gemini.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"github.com/dfanso/commit-msg/pkg/types"
1111
)
1212

13+
// GenerateCommitMessage asks Google Gemini to author a commit message for the
14+
// supplied repository changes and optional style instructions.
1315
func GenerateCommitMessage(config *types.Config, changes string, apiKey string, opts *types.GenerationOptions) (string, error) {
1416
// Prepare request to Gemini API
1517
prompt := types.BuildCommitPrompt(changes, opts)

internal/grok/grok.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"github.com/dfanso/commit-msg/pkg/types"
1313
)
1414

15+
// GenerateCommitMessage calls X.AI's Grok API to create a commit message from
16+
// the provided Git diff and generation options.
1517
func GenerateCommitMessage(config *types.Config, changes string, apiKey string, opts *types.GenerationOptions) (string, error) {
1618
// Prepare request to X.AI (Grok) API
1719
prompt := types.BuildCommitPrompt(changes, opts)

internal/ollama/ollama.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@ import (
1010
"github.com/dfanso/commit-msg/pkg/types"
1111
)
1212

13+
// OllamaRequest captures the prompt payload sent to an Ollama HTTP endpoint.
1314
type OllamaRequest struct {
1415
Model string `json:"model"`
1516
Prompt string `json:"prompt"`
1617
}
1718

19+
// OllamaResponse represents the non-streaming response from Ollama.
1820
type OllamaResponse struct {
1921
Response string `json:"response"`
2022
Done bool `json:"done"`
2123
}
2224

25+
// GenerateCommitMessage uses a locally hosted Ollama model to draft a commit
26+
// message from repository changes and optional style guidance.
2327
func GenerateCommitMessage(_ *types.Config, changes string, url string, model string, opts *types.GenerationOptions) (string, error) {
2428
// Use llama3:latest as the default model
2529
if model == "" {

pkg/types/prompt.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"strings"
66
)
77

8+
// CommitPrompt is the base instruction template sent to LLM providers before
9+
// appending repository changes and optional style guidance.
810
var CommitPrompt = `I need a concise git commit message based on the following changes from my Git repository.
911
Please generate a commit message that:
1012
1. Starts with a verb in the present tense (e.g., "Add", "Fix", "Update", "Feat", "Refactor", etc.)

pkg/types/types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ func (p LLMProvider) IsValid() bool {
1919
switch p {
2020
case ProviderOpenAI, ProviderClaude, ProviderGemini, ProviderGrok, ProviderGroq, ProviderOllama:
2121
return true
22+
// LLMProvider identifies the large language model backend used to author
23+
// commit messages.
2224
default:
2325
return false
2426
}
@@ -30,11 +32,14 @@ func GetSupportedProviders() []LLMProvider {
3032
ProviderClaude,
3133
ProviderGemini,
3234
ProviderGrok,
35+
// String returns the string form of the provider identifier.
3336
ProviderGroq,
3437
ProviderOllama,
3538
}
3639
}
3740

41+
// IsValid reports whether the provider is part of the supported set.
42+
3843
func GetSupportedProviderStrings() []string {
3944
providers := GetSupportedProviders()
4045
strings := make([]string, len(providers))
@@ -44,6 +49,8 @@ func GetSupportedProviderStrings() []string {
4449
return strings
4550
}
4651

52+
// GetSupportedProviders returns all available provider enums.
53+
4754
func ParseLLMProvider(s string) (LLMProvider, bool) {
4855
provider := LLMProvider(s)
4956
return provider, provider.IsValid()
@@ -55,6 +62,8 @@ type Config struct {
5562
Repos map[string]RepoConfig `json:"repos"`
5663
}
5764

65+
// GetSupportedProviderStrings returns the human-friendly names for providers.
66+
5867
// Repository configuration
5968
type RepoConfig struct {
6069
Path string `json:"path"`
@@ -63,6 +72,7 @@ type RepoConfig struct {
6372

6473
// Grok/X.AI API request structure
6574
type GrokRequest struct {
75+
// ParseLLMProvider converts a string into an LLMProvider enum when supported.
6676
Messages []Message `json:"messages"`
6777
Model string `json:"model"`
6878
Stream bool `json:"stream"`

0 commit comments

Comments
 (0)