@@ -19,6 +19,7 @@ def initialize(options = {})
1919 @git_service = Services ::GitService . new
2020 @ai_service = Services ::AIService . new ( @settings )
2121 @history_service = Services ::HistoryService . new
22+ @validator = Validators ::CommitMessageValidator . new ( get_commit_style )
2223 @retry_count = 0
2324 end
2425
@@ -27,8 +28,11 @@ def execute
2728 status = @git_service . repository_status
2829 validate_repository ( status )
2930
31+ # Get staged files
32+ staged_files = @git_service . get_staged_files
33+
3034 # Get and validate changes
31- diff = @git_service . get_staged_diff
35+ diff = @git_service . get_staged_diff ( staged_files )
3236 validate_changes ( diff )
3337
3438 # Show diff preview if requested
@@ -112,6 +116,24 @@ def generate_message_with_style(diff, style, scope)
112116 message
113117 end
114118
119+ # Message Validation Methods
120+ def validate_message ( message )
121+ result = @validator . validate ( message )
122+
123+ if result [ :errors ] . any?
124+ puts "\n ❌ Validation errors:" . red
125+ result [ :errors ] . each { |error | puts @validator . format_error ( error ) }
126+ end
127+
128+ if result [ :warnings ] . any?
129+ puts "\n ⚠️ Suggestions:" . yellow
130+ result [ :warnings ] . each { |warning | puts @validator . format_warning ( warning ) }
131+ end
132+
133+ puts "\n Please edit the message to fix these errors." if result [ :errors ] . any?
134+ result
135+ end
136+
115137 # Message Handling Methods
116138 def handle_message ( message , diff )
117139 formatted = Formatters ::MessageFormatter . new . format ( message )
@@ -124,37 +146,23 @@ def handle_message(message, diff)
124146 end
125147 end
126148
127- def validate_message ( message )
128- validator = Validators ::CommitMessageValidator . new
129- validator . validate ( message )
130- end
131-
132149 def display_message_and_validation ( formatted_message , validation )
133- provider = @settings . get ( :ai_provider )
134- model = @settings . get ( :ai_model )
135- model_info = "(#{ provider } /#{ model } )" . light_black
136-
137- puts "\n 📝 Generated commit message #{ model_info } :" . blue
150+ puts "\n 📝 Generated commit message (#{ @settings . get ( :ai_provider ) } /#{ @settings . get ( :ai_model ) } ):" . blue
138151 puts formatted_message
139152
140- display_validation_errors ( validation [ :errors ] ) if validation [ :errors ] . any?
153+ return unless validation [ :errors ] . any? || validation [ :warnings ] . any?
141154
142- return unless validation [ :warnings ] . any?
143-
144- display_validation_warnings ( validation [ :warnings ] )
145- end
155+ if validation [ :errors ] . any?
156+ puts " \n ❌ Validation errors:" . red
157+ validation [ :errors ] . each { | error | puts @validator . format_error ( error ) }
158+ end
146159
147- def display_validation_errors ( errors )
148- puts "\n ❌ Validation errors:" . red
149- validator = Validators ::CommitMessageValidator . new
150- errors . each { |error | puts validator . format_error ( error ) }
151- puts "\n Please edit the message to fix these errors." . yellow
152- end
160+ if validation [ :warnings ] . any?
161+ puts "\n ⚠️ Suggestions:" . yellow
162+ validation [ :warnings ] . each { |warning | puts @validator . format_warning ( warning ) }
163+ end
153164
154- def display_validation_warnings ( warnings )
155- puts "\n ⚠️ Suggestions:" . yellow
156- validator = Validators ::CommitMessageValidator . new
157- warnings . each { |warning | puts validator . format_warning ( warning ) }
165+ puts "\n Please edit the message to fix these errors." if validation [ :errors ] . any?
158166 end
159167
160168 def prompt_user_action
0 commit comments