Skip to content

Comments

refactor: implement separate prompt templates for commit messages#23

Merged
billybonks merged 1 commit intomasterfrom
feat/replace-formatting-rules
Mar 11, 2025
Merged

refactor: implement separate prompt templates for commit messages#23
billybonks merged 1 commit intomasterfrom
feat/replace-formatting-rules

Conversation

@billybonks
Copy link
Contributor

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.

Copy link

@managerbot-app managerbot-app bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏿 👎🏿 review comments so that we know what works and what does not work

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?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 || '')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@billybonks billybonks force-pushed the feat/replace-formatting-rules branch from fd7c062 to 9e21eac Compare March 11, 2025 12:35
@billybonks billybonks merged commit 0f8b7e1 into master Mar 11, 2025
2 checks passed
@billybonks billybonks deleted the feat/replace-formatting-rules branch March 11, 2025 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant