-
Notifications
You must be signed in to change notification settings - Fork 2
refactor: implement separate prompt templates for commit messages #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
52 changes: 52 additions & 0 deletions
52
lib/committer/config/defaults/commit_message_and_body.prompt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| You are an experienced software developer tasked with creating a commit message based on a git diff. Your goal is to produce a clear, concise, and informative commit message. | ||
|
|
||
| First, carefully analyze the following git diff: | ||
|
|
||
| <git_diff> | ||
| {{DIFF}} | ||
| </git_diff> | ||
|
|
||
| Here are the available scopes (if any): | ||
|
|
||
| <scopes> | ||
| {{SCOPES}} | ||
| </scopes> | ||
|
|
||
| <user_context> | ||
| {{CONTEXT}} | ||
| </user_context> | ||
|
|
||
| Please follow these instructions to generate the commit message: | ||
|
|
||
| 1. Analyze the git diff and determine the most appropriate commit type from the following options: | ||
| - feat: A new feature | ||
| - fix: A bug fix | ||
| - docs: Documentation only changes | ||
| - style: Changes that do not affect the meaning of the code | ||
| - refactor: A code change that neither fixes a bug nor adds a feature | ||
| - perf: A code change that improves performance | ||
| - test: Adding missing tests or correcting existing tests | ||
| - chore: Changes to the build process or auxiliary tools and libraries | ||
|
|
||
|
|
||
| 2. Adhere to these message guidelines: | ||
| - Keep the summary under 70 characters | ||
| - Use imperative, present tense (e.g., "add" not "added" or "adds") | ||
| - Do not end the summary with a period | ||
| - Be concise but descriptive | ||
|
|
||
| 3. Format the commit message as follows: | ||
| - If a scope is available: <type>(<scope>): <description> | ||
| - If no scope is available: <type>: <description> | ||
|
|
||
| 4 Body Guidelines: | ||
| - Add a blank line between summary and body | ||
| - Use the body to explain why the change was made, incorporating the user's context, defined in <user_context> | ||
| - Wrap each line in the body at 80 characters maximum | ||
| - Break the body into multiple paragraphs if needed | ||
|
|
||
| [Your concise commit message in the specified format] | ||
| [blank line] | ||
| [Your detailed commit message body] | ||
|
|
||
| Respond ONLY with the commit message text (message and body), nothing else. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| You are an experienced software developer tasked with creating a commit message based on a git diff. Your goal is to produce a clear, concise, and informative commit message. | ||
|
|
||
| First, carefully analyze the following git diff: | ||
|
|
||
| <git_diff> | ||
| {{DIFF}} | ||
| </git_diff> | ||
|
|
||
| Here are the available scopes (if any): | ||
|
|
||
| <scopes> | ||
| {{SCOPES}} | ||
| </scopes> | ||
|
|
||
| Please follow these instructions to generate the commit message: | ||
|
|
||
| 1. Analyze the git diff and determine the most appropriate commit type from the following options: | ||
| - feat: A new feature | ||
| - fix: A bug fix | ||
| - docs: Documentation only changes | ||
| - style: Changes that do not affect the meaning of the code | ||
| - refactor: A code change that neither fixes a bug nor adds a feature | ||
| - perf: A code change that improves performance | ||
| - test: Adding missing tests or correcting existing tests | ||
| - chore: Changes to the build process or auxiliary tools and libraries | ||
|
|
||
|
|
||
| 2. Adhere to these message guidelines: | ||
| - Keep the summary under 70 characters | ||
| - Use imperative, present tense (e.g., "add" not "added" or "adds") | ||
| - Do not end the summary with a period | ||
| - Be concise but descriptive | ||
|
|
||
| 3. Format the commit message as follows: | ||
| - If a scope is available: <type>(<scope>): <description> | ||
| - If no scope is available: <type>: <description> | ||
|
|
||
| Respond ONLY with the commit message line, nothing else. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,69 +2,36 @@ | |
|
|
||
| module Committer | ||
| module PromptTemplates | ||
| 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? | ||
| Committer::PromptTemplates.build_prompt_summary_only | ||
| else | ||
| Committer::PromptTemplates.build_prompt_summary_and_body | ||
| end | ||
| prompt_template | ||
| .gsub('{{DIFF}}', diff) | ||
| .gsub('{{SCOPES}}', build_scopes_list(scopes)) | ||
| .gsub('{{CONTEXT}}', commit_context || '') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using a more defensive approach with |
||
| end | ||
|
|
||
| def self.load_scopes | ||
| scopes = Committer::Config::Accessor.instance[:scopes] || [] | ||
| def self.build_scopes_list(scopes) | ||
| return 'DO NOT include a scope in your commit message' if scopes.empty? | ||
|
|
||
| scope_list = "\nScopes:\n#{scopes.map { |s| "- #{s}" }.join("\n")}" | ||
|
|
||
| "- Choose an appropriate scope from the list above if relevant to the change \n#{scope_list}" | ||
| end | ||
|
|
||
| def self.commit_message_guidelines | ||
| <<~PROMPT | ||
| #{load_formatting_rules} | ||
|
|
||
| # Formatting rules with body: | ||
| <message> | ||
|
|
||
| <blank line> | ||
| <body with more detailed explanation> | ||
|
|
||
| #{load_scopes} | ||
|
|
||
| # Message Guidelines: | ||
| - Keep the summary under 70 characters | ||
| - Use imperative, present tense (e.g., "add" not "added" or "adds") | ||
| - Do not end the summary with a period | ||
| - Be concise but descriptive in the summary | ||
|
|
||
| # Body Guidelines: | ||
| - Add a blank line between summary and body | ||
| - Use the body to explain why the change was made, incorporating the user's context | ||
| - Wrap each line in the body at 80 characters maximum | ||
| - Break the body into multiple paragraphs if needed | ||
|
|
||
| Git Diff: | ||
| ``` | ||
| %<diff>s | ||
| ``` | ||
| PROMPT | ||
| end | ||
|
|
||
| def self.build_prompt_summary_only | ||
| <<~PROMPT | ||
| Below is a git diff of staged changes. Please analyze it and create a commit message following the formatting rules format with ONLY a message line (NO body): | ||
|
|
||
| #{commit_message_guidelines} | ||
|
|
||
| Respond ONLY with the commit message line, nothing else. | ||
| PROMPT | ||
| load_prompt(Committer::Config::Constants::COMMIT_MESSAGE_ONLY_PROMPT_FILE_NAME) | ||
| end | ||
|
|
||
| def self.build_prompt_summary_and_body | ||
| <<~PROMPT | ||
| Below is a git diff of staged changes. Please analyze it and create a commit message following the formatting rules format with a summary line and a detailed body: | ||
|
|
||
| #{commit_message_guidelines} | ||
| User's context for this change: %<commit_context>s | ||
| load_prompt(Committer::Config::Constants::COMMIT_MESSAGE_AND_BODY_PROMPT_FILE_NAME) | ||
| end | ||
|
|
||
| Respond ONLY with the commit message text (message and body), nothing else. | ||
| PROMPT | ||
| def self.load_prompt(file_name) | ||
| Committer::Config::Accessor.instance.read_path_prioritized_file(file_name) | ||
| end | ||
| end | ||
| end | ||
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
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
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.
There was a problem hiding this comment.
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.