Skip to content

Commit c65a027

Browse files
committed
Refactor logging and build prompt functionality
* feat: Add output file logging in parse_args * feat: Include project title in prompt generation * fix: Handle missing version gracefully in build_prompt * chore: Clean up variable assignments in build_prompt * chore: Enhance prompt content by appending final instructions
1 parent 1ad11bf commit c65a027

File tree

10 files changed

+73
-29
lines changed

10 files changed

+73
-29
lines changed

src/giv.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ parse_args() {
366366
print_debug " Template Directory: ${template_dir}"
367367
print_debug " Config File: ${config_file}"
368368
print_debug " Config Loaded: ${is_config_loaded}"
369-
print_debug " Output File: ${output_file}"
370369
print_debug " TODO Files: ${todo_files}"
371370
print_debug " TODO Pattern: ${todo_pattern}"
372371
print_debug " Version File: ${version_file}"
@@ -375,6 +374,7 @@ parse_args() {
375374
print_debug " Model Mode: ${model_mode}"
376375
print_debug " API Model: ${api_model}"
377376
print_debug " API URL: ${api_url}"
377+
print_debug " Output File: ${output_file}"
378378
print_debug " Output Mode: ${output_mode}"
379379
print_debug " Output Version: ${output_version}"
380380
print_debug " Prompt File: ${prompt_file}"
@@ -593,8 +593,12 @@ cmd_announcement() {
593593

594594
prompt_file_name="${PROMPT_DIR}/announcement_prompt.md"
595595
tmp_prompt_file=$(portable_mktemp "announcement_prompt_XXXXXX.md")
596-
build_prompt "${prompt_file_name}" "${summaries_file}" >"${tmp_prompt_file}"
596+
project_title="$(parse_project_title "${summaries_file}")"
597+
print_debug "Project title: ${project_title}"
598+
build_prompt --project-title "${project_title}" "${prompt_file_name}" "${summaries_file}" >"${tmp_prompt_file}"
597599

600+
print_debug "Generated prompt file: ${tmp_prompt_file}"
601+
print_info "$(cat "${tmp_prompt_file}" || true)"
598602
generate_from_prompt "${tmp_prompt_file}" \
599603
"${output_file:-${announce_file}}" "${model_mode}"
600604
}

src/helpers.sh

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,17 @@ replace_tokens() {
110110
# Exports GIV_TOKEN_SUMMARY (and any of PROJECT_TITLE, VERSION, EXAMPLE, RULES
111111
# if passed) then runs replace_tokens on the template.
112112
build_prompt() {
113-
project_title=$(parse_project_title)
114-
version="${GIV_TOKEN_VERSION:-}"
115-
example="${GIV_TOKEN_EXAMPLE:-}"
116-
rules="${GIV_TOKEN_RULES:-}"
113+
project_title="$(parse_project_title)"
114+
115+
version="${output_version:-${GIV_TOKEN_VERSION:-}}"
116+
if [ -z "${version}" ] || [ "${version}" = "auto" ]; then
117+
print_debug "No version set or version is 'auto', trying to find it from version file"
118+
# Try to find the version file and extract the version
119+
version_file="$(find_version_file)"
120+
version="$(get_version_info --current "${version_file:-}")"
121+
fi
122+
example=""
123+
rules=""
117124
# parse flags
118125
while [ $# -gt 2 ]; do
119126
case "$1" in
@@ -156,13 +163,19 @@ build_prompt() {
156163
# export our tokens
157164
export GIV_TOKEN_SUMMARY
158165
GIV_TOKEN_SUMMARY=$(cat "${diff_file}")
159-
[ -n "$project_title" ] && export GIV_TOKEN_PROJECT_TITLE="$project_title"
160-
[ -n "$version" ] && export GIV_TOKEN_VERSION="$version"
161-
[ -n "$example" ] && export GIV_TOKEN_EXAMPLE="$example"
162-
[ -n "$rules" ] && export GIV_TOKEN_RULES="$rules"
163166

164-
# run the replacement
165-
replace_tokens <"$prompt_template"
167+
export GIV_TOKEN_PROJECT_TITLE="${project_title:-${GIV_TOKEN_PROJECT_TITLE}}"
168+
export GIV_TOKEN_VERSION="${version:-${GIV_TOKEN_VERSION}}"
169+
export GIV_TOKEN_EXAMPLE="${example:-${GIV_TOKEN_EXAMPLE}}"
170+
export GIV_TOKEN_RULES="${rules:-${GIV_TOKEN_RULES}}"
171+
172+
# Append the extra instructions to the prompt content before passing to replace_tokens
173+
{
174+
cat "${prompt_template}"
175+
printf '\nOutput just the final content—no extra commentary or code fencing. '
176+
printf 'Use only information contained in this prompt and the summaries provided above.'
177+
} | replace_tokens
178+
return
166179
}
167180

168181
# Locate the project from the codebase. Looks for common project files

templates/announcement_prompt.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# Summary of Changes
2+
13
[SUMMARY]
24

35
Write one engaging blog post announcing the [VERSION] release of [PROJECT_TITLE], using the following guidelines:
@@ -37,6 +39,4 @@ Write one engaging blog post announcing the [VERSION] release of [PROJECT_TITLE]
3739
• Craft a narrative that flows logically from introduction to CTA
3840
• Ensure all technical details are translated into user-friendly language
3941

40-
Output just the final blog post—no extra commentary and using only information from the summaries provided above.
41-
42-
[RULES]
42+
[RULES]

templates/changelog_prompt.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# Summary of Changes
2+
13
[SUMMARY]
4+
5+
## Task
6+
27
Generate a comprehensive changelog in the Keep a Changelog format for [PROJECT_TITLE] [VERSION]:
38

49
1. Format Requirements:
@@ -32,12 +37,13 @@ Generate a comprehensive changelog in the Keep a Changelog format for [PROJECT_T
3237

3338
[EXAMPLE]
3439

35-
Processing Instructions:
40+
## Processing Instructions
41+
3642
- Analyze all provided summaries
3743
- Identify release boundaries
3844
- Group changes by type
3945
- Maintain chronological order
4046
- Ensure consistent formatting
4147
- Focus on technical accuracy
4248

43-
[RULES]
49+
[RULES]

templates/message_prompt.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
## Summary of Changes
2+
13
[SUMMARY]
4+
5+
## Instructions
6+
27
Write a git commit message for the provided git history following the Keep a Changelog standard:
38

49
1. Format Requirements:
@@ -40,3 +45,4 @@ Write a git commit message for the provided git history following the Keep a Cha
4045

4146
[EXAMPLE]
4247

48+
[RULES]

templates/post_example.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```
2+
🚀 BIG NEWS! 🚀
3+
We've just released v1.2.3 with game-changing authentication improvements! 🛡️
4+
✨ 50% faster login times
5+
✨ Enhanced security with JWT tokens
6+
✨ Seamless cross-platform experience
7+
8+
Read the full announcement and upgrade now! [link] #SoftwareRelease #NewFeatures #PerformanceMatters
9+
```

templates/post_prompt.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
## Summary of Changes
2+
13
[SUMMARY]
4+
5+
## Instructions
6+
27
Generate an engaging social media post announcing the [PROJECT_TITLE] [VERSION] release:
38

49
1. Content Requirements:
@@ -31,15 +36,7 @@ Generate an engaging social media post announcing the [PROJECT_TITLE] [VERSION]
3136

3237
5. Example Format:
3338

34-
```
35-
🚀 BIG NEWS! 🚀
36-
We've just released v1.2.3 with game-changing authentication improvements! 🛡️
37-
✨ 50% faster login times
38-
✨ Enhanced security with JWT tokens
39-
✨ Seamless cross-platform experience
40-
41-
Read the full announcement and upgrade now! [link] #SoftwareRelease #NewFeatures #PerformanceMatters
42-
```
39+
[EXAMPLE]
4340

4441
6. Processing Instructions:
4542

@@ -49,4 +46,4 @@ Read the full announcement and upgrade now! [link] #SoftwareRelease #NewFeatures
4946
- Focus on driving engagement and clicks
5047
- Ensure all links and hashtags are included
5148

52-
[RULES]
49+
[RULES]

templates/release_notes_prompt.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
## Summary of Changes
2+
13
[SUMMARY]
4+
5+
## Instructions
6+
27
Write one comprehensive release notes document [PROJECT_TITLE] [VERSION] from the provided change summaries, following these guidelines:
38

49
1. Structure
@@ -34,4 +39,4 @@ Write one comprehensive release notes document [PROJECT_TITLE] [VERSION] from th
3439

3540
[EXAMPLE]
3641
[RULES]
37-
Output only the final release notes—no extra commentary.
42+

templates/summary_prompt.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ Write a structured, Keep a Changelog–style summary of the provided git diff. D
5959

6060
[EXAMPLE]
6161
[RULES]
62-
Output only the completed summary—no additional commentary.
62+

tests/replace_tokens.bats

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ Summary:
138138
Line A
139139
Line B
140140
Done.
141+
142+
Output just the final content—no extra commentary or code fencing. Use only information contained in this prompt and the summaries provided above.
141143
EOF
142144
}
143145

@@ -180,5 +182,7 @@ Rules:
180182
1. First rule
181183
2. Second rule
182184
185+
186+
Output just the final content—no extra commentary or code fencing. Use only information contained in this prompt and the summaries provided above.
183187
EOF
184188
}

0 commit comments

Comments
 (0)