Module: Committer::PromptTemplates

Defined in:
lib/committer/prompt_templates.rb

Constant Summary collapse

FORMATTING_RULES_PATH =
File.join(File.dirname(__FILE__), 'formatting_rules.txt')

Class Method Summary collapse

Class Method Details

.build_prompt_summary_and_bodyObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/committer/prompt_templates.rb', line 61

def self.build_prompt_summary_and_body
  "    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:\n\n    \#{commit_message_guidelines}\n    User's context for this change: %<commit_context>s\n\n    Respond ONLY with the commit message text (message and body), nothing else.\n  PROMPT\nend\n"

.build_prompt_summary_onlyObject



51
52
53
54
55
56
57
58
59
# File 'lib/committer/prompt_templates.rb', line 51

def self.build_prompt_summary_only
  "    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):\n\n    \#{commit_message_guidelines}\n\n    Respond ONLY with the commit message line, nothing else.\n  PROMPT\nend\n"

.commit_message_guidelinesObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/committer/prompt_templates.rb', line 20

def self.commit_message_guidelines
  "    \#{load_formatting_rules}\n\n    # Formatting rules with body:\n    <message>\n\n    <blank line>\n    <body with more detailed explanation>\n\n    \#{load_scopes}\n\n    # Message Guidelines:\n    - Keep the summary under 70 characters\n    - Use imperative, present tense (e.g., \"add\" not \"added\" or \"adds\")\n    - Do not end the summary with a period\n    - Be concise but descriptive in the summary\n\n    # Body Guidelines:\n    - Add a blank line between summary and body\n    - Use the body to explain why the change was made, incorporating the user's context\n    - Wrap each line in the body at 80 characters maximum\n    - Break the body into multiple paragraphs if needed\n\n    Git Diff:\n    ```\n    %<diff>s\n    ```\n  PROMPT\nend\n"

.load_formatting_rulesObject



7
8
9
# File 'lib/committer/prompt_templates.rb', line 7

def self.load_formatting_rules
  File.read(FORMATTING_RULES_PATH)
end

.load_scopesObject



11
12
13
14
15
16
17
18
# File 'lib/committer/prompt_templates.rb', line 11

def self.load_scopes
  scopes = Committer::Config::Accessor.instance[: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