Skip to content

Commit ee2fa12

Browse files
authored
Merge pull request #35 from m7medVision/feature/per-repo-config
feat(config): add support for per-repository configuration overrides
2 parents 35c3ac4 + 4df61cb commit ee2fa12

5 files changed

Lines changed: 152 additions & 106 deletions

File tree

README.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ AI-powered Git commit message generator that analyzes your staged changes and ou
1212
- Generates configurable number of commit message suggestions from your staged diff
1313
- Generates 10 pull request titles based on the diff between the current branch and a target branch
1414
- Providers: GitHub Copilot (default), OpenAI, Anthropic (Claude Code CLI)
15-
- Multi-language support: English and Spanish
15+
- Multi-language support: Any language (English, Arabic, Korean, etc.)
1616
- Interactive config to pick provider/model/language and set keys
1717
- Simple output suitable for piping into TUI menus (one message per line)
1818

@@ -81,7 +81,6 @@ Contains API keys, tokens, and provider-specific settings. **Do not share this f
8181

8282
```yaml
8383
active_provider: copilot # default if a GitHub token is found
84-
language: en # commit message language: "en" (English) or "es" (Spanish)
8584
providers:
8685
copilot:
8786
api_key: "$GITHUB_TOKEN" # Uses GitHub token; token is exchanged internally
@@ -94,29 +93,33 @@ providers:
9493
anthropic:
9594
model: "claude-haiku-4-5" # Uses Claude Code CLI - no API key needed
9695
num_suggestions: 10 # Number of commit suggestions to generate
97-
# Custom provider example (e.g., local Ollama):
98-
# local:
99-
# api_key: "not-needed"
100-
# model: "llama3.1:8b"
101-
# endpoint_url: "http://localhost:11434/v1"
10296
```
10397
104-
#### Anthropic Provider (Claude Code CLI)
98+
> [!NOTE]
99+
> `.lazycommit.yaml: language` is removed and please use `.lazycommit.prompts.yaml` instead.
105100

106-
The Anthropic provider integrates with your local [Claude Code CLI](https://github.com/anthropics/claude-code) installation:
101+
### 2. Prompt Configuration (`~/.config/.lazycommit.prompts.yaml`)
102+
Contains prompt templates and message configurations. **Safe to share in dotfiles and Git.**
103+
104+
```yaml
105+
language: English # commit message language (e.g., "English", "Arabic", "Korean")
106+
system_message: "You are a helpful assistant that generates git commit messages, and pull request titles."
107+
commit_message_template: "Based on the following git diff, generate 10 conventional commit messages. Each message should be on a new line, without any numbering or bullet points:\n\n%s"
108+
pr_title_template: "Based on the following git diff, generate 10 pull request title suggestions. Each title should be on a new line, without any numbering or bullet points:\n\n%s"
109+
```
107110

108-
- **No API key required**: Uses your existing Claude Code authentication
109-
- **Fast and cost-effective**: Leverages Claude Haiku model
110-
- **Configurable**: Set custom number of suggestions per provider
111+
### Per-Repository Configuration
111112

112-
Requirements:
113-
- Claude Code CLI installed and authenticated
114-
- Command `claude` available in PATH
113+
You can override the prompt configuration on a per-repository basis by creating a `.lazycommit.prompts.yaml` file in the root of your git repository. This is useful for projects that require different languages or commit message formats.
115114

116-
### 2. Prompt Configuration (`~/.config/.lazycommit.prompts.yaml`)
117-
Contains prompt templates and message configurations. **Safe to share in dotfiles and Git.**
115+
If a field is missing in your repository-local configuration, the value from the global configuration will be used.
118116

119-
This file is automatically created on first run with sensible defaults:
117+
Example `.lazycommit.prompts.yaml` for a Korean project:
118+
```yaml
119+
language: Korean
120+
commit_message_template: "Based on the following git diff, generate 5 conventional commit messages:\n\n%s"
121+
```
122+
This file is automatically created on first run in the global config directory with sensible defaults:
120123

121124
```yaml
122125
system_message: "You are a helpful assistant that generates git commit messages, and pull request titles."
@@ -158,12 +161,14 @@ providers:
158161

159162
### Language Configuration
160163

161-
lazycommit supports generating commit messages in different languages. Set the `language` field in your config:
164+
lazycommit supports generating commit messages in any language. Set the `language` field in your prompt config (`.lazycommit.prompts.yaml`):
162165

163166
```yaml
164-
language: es # Spanish
167+
language: Spanish
168+
# or
169+
language: Arabic
165170
# or
166-
language: en # English (default)
171+
language: English # (default)
167172
```
168173

169174
You can also configure it interactively:
@@ -174,10 +179,6 @@ lazycommit config set # Select language in the interactive menu
174179

175180
The language setting automatically instructs the AI to generate commit messages in the specified language, regardless of the provider used.
176181

177-
**Supported languages:**
178-
- `en` - English (default)
179-
- `es` - Spanish (Español)
180-
181182
## Integration with TUI Git clients
182183

183184
Because `lazycommit commit` prints plain lines, it plugs nicely into menu UIs.

cmd/config.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,19 @@ func runInteractiveConfig() {
103103

104104
// Language configuration
105105
currentLanguage := config.GetLanguage()
106+
languageOptions := []string{"English", "Spanish", "Other..."}
106107
languagePrompt := &survey.Select{
107108
Message: "Choose a language for commit messages:",
108-
Options: []string{"English (en)", "Español (es)"},
109+
Options: languageOptions,
109110
Default: func() string {
110-
if currentLanguage == "es" {
111-
return "Español (es)"
111+
switch currentLanguage {
112+
case "Spanish":
113+
return "Spanish"
114+
case "English":
115+
return "English"
116+
default:
117+
return "Other..."
112118
}
113-
return "English (en)"
114119
}(),
115120
}
116121
var selectedLanguage string
@@ -120,19 +125,31 @@ func runInteractiveConfig() {
120125
return
121126
}
122127

123-
// Extract language code from selection
124-
langCode := "en"
125-
if selectedLanguage == "Español (es)" {
126-
langCode = "es"
128+
var langValue string
129+
switch selectedLanguage {
130+
case "Spanish":
131+
langValue = "Spanish"
132+
case "English":
133+
langValue = "English"
134+
case "Other...":
135+
otherPrompt := &survey.Input{
136+
Message: "Enter language name (e.g., 'Arabic', 'Korean', 'French'):",
137+
Default: currentLanguage,
138+
}
139+
err = survey.AskOne(otherPrompt, &langValue)
140+
if err != nil {
141+
fmt.Println(err.Error())
142+
return
143+
}
127144
}
128145

129-
if langCode != currentLanguage {
130-
err := config.SetLanguage(langCode)
146+
if langValue != "" && langValue != currentLanguage {
147+
err := config.SetLanguage(langValue)
131148
if err != nil {
132149
fmt.Printf("Error setting language: %v\n", err)
133150
return
134151
}
135-
fmt.Printf("Language set to: %s\n", langCode)
152+
fmt.Printf("Language set to: %s\n", langValue)
136153
}
137154

138155
// API key configuration - skip for copilot and anthropic

internal/config/config.go

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ type ProviderConfig struct {
2323
type Config struct {
2424
Providers map[string]ProviderConfig `mapstructure:"providers"`
2525
ActiveProvider string `mapstructure:"active_provider"`
26-
Language string `mapstructure:"language"`
2726
}
2827

2928
var cfg *Config
@@ -32,6 +31,7 @@ func InitConfig() {
3231
viper.SetConfigName(".lazycommit")
3332
viper.SetConfigType("yaml")
3433
viper.AddConfigPath(getConfigDir())
34+
3535
viper.SetConfigFile(filepath.Join(getConfigDir(), ".lazycommit.yaml"))
3636

3737
if token, err := LoadGitHubToken(); err == nil && token != "" {
@@ -43,13 +43,8 @@ func InitConfig() {
4343
viper.SetDefault("providers.openai.model", "openai/gpt-5-mini")
4444
}
4545

46-
// Set defaults for anthropic provider
4746
viper.SetDefault("providers.anthropic.model", "claude-haiku-4-5")
4847
viper.SetDefault("providers.anthropic.num_suggestions", 10)
49-
50-
// Set default language
51-
viper.SetDefault("language", "en")
52-
5348
viper.AutomaticEnv()
5449

5550
if err := viper.ReadInConfig(); err != nil {
@@ -73,7 +68,6 @@ func InitConfig() {
7368
os.Exit(1)
7469
}
7570

76-
// Initialize prompt configuration
7771
InitPromptConfig()
7872
}
7973

@@ -290,25 +284,6 @@ func SetNumSuggestions(provider, numSuggestions string) error {
290284
return viper.WriteConfig()
291285
}
292286

293-
func GetLanguage() string {
294-
if cfg == nil {
295-
InitConfig()
296-
}
297-
if cfg.Language == "" {
298-
return "en" // Default to English
299-
}
300-
return cfg.Language
301-
}
302-
303-
func SetLanguage(language string) error {
304-
if cfg == nil {
305-
InitConfig()
306-
}
307-
cfg.Language = language
308-
viper.Set("language", language)
309-
return viper.WriteConfig()
310-
}
311-
312287
func getConfigDir() string {
313288
if xdgConfig := os.Getenv("XDG_CONFIG_HOME"); xdgConfig != "" {
314289
return xdgConfig

0 commit comments

Comments
 (0)