Skip to content

Commit 3c3ce7f

Browse files
authored
Merge pull request #31 from Tomas-vilte/dev
refactor: Improve AI service and error handling
2 parents 88e3874 + 3597e32 commit 3c3ce7f

5 files changed

Lines changed: 9 additions & 5 deletions

File tree

internal/domain/ports/ai_service.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"github.com/Tomas-vilte/MateCommit/internal/domain/models"
66
)
77

8-
type AIProvider interface {
8+
// CommitSummarizer es una interfaz que define el servicio para generar sugerencias de commits.
9+
type CommitSummarizer interface {
10+
//GenerateSuggestions genera una lista de sugerencias de mensajes de commit.
911
GenerateSuggestions(ctx context.Context, info models.CommitInfo, count int) ([]models.CommitSuggestion, error)
1012
}
1113

internal/i18n/locales/active.en.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ pr_changes_section = "Key Changes"
170170
error_gemini_client = "Error creating Gemini client: {{.Error}}"
171171
response_empty = "Empty AI response"
172172
title_not_found = "The title was not found in the answer"
173+
error_empty_prompt = "The prompt cannot be empty"
173174

174175
[suggestion_header]
175176
other = "=========[ Suggestion {{.Number}} ]========="

internal/i18n/locales/active.es.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ other = "❌ Error al iniciar Gemini: {{.Error}}"
3838
other = "🔍 Analizando cambios..."
3939

4040
[error_missing_api_key]
41-
other = "La variable de entorno, GEMINI_API_KEY no esta configurada"
41+
other = "La GEMINI_API_KEY no está configurada"
4242

4343
[error_generating_content]
4444
other = "Error generando el contenido: {{.Error}}"
@@ -178,6 +178,7 @@ pr_changes_section = "Cambios Clave"
178178
error_gemini_client = "Error al crear el cliente de Gemini: {{.Error}}"
179179
response_empty = "Respuesta de la IA vacia"
180180
title_not_found = "No se encontro el titulo en la respuesta"
181+
error_empty_prompt = "El prompt no puede estar vacio"
181182

182183
[suggestion_header]
183184
other = "=========[ Sugerencias {{.Number}} ]========="

internal/infrastructure/ai/gemini/gemini_pr_summarizer_service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func NewGeminiPRSummarizer(ctx context.Context, cfg *config.Config, trans *i18n.
4747

4848
func (gps *GeminiPRSummarizer) GeneratePRSummary(ctx context.Context, prompt string) (models.PRSummary, error) {
4949
if prompt == "" {
50-
msg := gps.trans.GetMessage("error_empty_prompt", 0, nil)
50+
msg := gps.trans.GetMessage("gemini_service.error_empty_prompt", 0, nil)
5151
return models.PRSummary{}, fmt.Errorf("%s", msg)
5252
}
5353

internal/services/commit_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212

1313
type CommitService struct {
1414
git ports.GitService
15-
ai ports.AIProvider
15+
ai ports.CommitSummarizer
1616
ticketManager ports.TickerManager
1717
config *config.Config
1818
trans *i18n.Translations
1919
}
2020

21-
func NewCommitService(git ports.GitService, ai ports.AIProvider, ticketManager ports.TickerManager, cfg *config.Config, trans *i18n.Translations) *CommitService {
21+
func NewCommitService(git ports.GitService, ai ports.CommitSummarizer, ticketManager ports.TickerManager, cfg *config.Config, trans *i18n.Translations) *CommitService {
2222
return &CommitService{
2323
git: git,
2424
ai: ai,

0 commit comments

Comments
 (0)