refactor: implement separate prompt templates for commit messages#23
Merged
billybonks merged 1 commit intomasterfrom Mar 11, 2025
Merged
refactor: implement separate prompt templates for commit messages#23billybonks merged 1 commit intomasterfrom
billybonks merged 1 commit intomasterfrom
Conversation
| def self.load_formatting_rules | ||
| Committer::Config::Accessor.instance.load_formatting_rules | ||
| def self.build_prompt(diff, scopes, commit_context) | ||
| prompt_template = if commit_context.nil? || commit_context.empty? |
There was a problem hiding this comment.
Consider passing these parameters as a hash to make the method more flexible to future changes.
| prompt_template | ||
| .gsub('{{DIFF}}', diff) | ||
| .gsub('{{SCOPES}}', build_scopes_list(scopes)) | ||
| .gsub('{{CONTEXT}}', commit_context || '') |
There was a problem hiding this comment.
Consider using a more defensive approach with commit_context.to_s in case commit_context is not nil but not a string.
| it 'builds prompt with scopes' do | ||
| prompt = generator.build_commit_prompt | ||
| expect(prompt).to include('Choose an appropriate scope from the list above') | ||
| expect(prompt).to include('Scopes:') |
There was a problem hiding this comment.
This test may have become flaky after removing the explicit check for 'Choose an appropriate scope from the list above'. Consider adding it back or updating test expectations to match the new behavior.
This change replaces the single formatting rules file with two separate prompt templates - one for commit messages with only a summary and another for messages with both summary and body. The refactoring addresses the challenge of creating a single template that works well for both scenarios, which was difficult to maintain and required powerful models to parse correctly. The implementation adds default prompt files and updates the code to select the appropriate template based on whether a commit context is provided. This gives users the flexibility to customize either format independently while maintaining consistent behavior.
fd7c062 to
9e21eac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change replaces the single formatting rules file with two separate prompt templates - one for commit messages with only a summary and another for messages with both summary and body. The refactoring addresses the challenge of creating a single template that works well for both scenarios, which was difficult to maintain and required powerful models to parse correctly. The implementation adds default prompt files and updates the code to select the appropriate template based on whether a commit context is provided. This gives users the flexibility to customize either format independently while maintaining consistent behavior.