feat: add configurable line limit and split logic for changelog updates
This commit is contained in:
1 file changed
+25
-14
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
update-changelog-with-llm() {
|
||||
local num_lines="${1:-100}"
|
||||
|
||||
# Check if CHANGELOG.md exists
|
||||
if [[ ! -f "CHANGELOG.md" ]]; then
|
||||
echo "Error: CHANGELOG.md not found in the current directory."
|
||||
@@ -16,23 +18,31 @@ update-changelog-with-llm() {
|
||||
# Create tmp directory if it doesn't exist
|
||||
mkdir -p tmp
|
||||
|
||||
# Split CHANGELOG.md into the portion we'll send to the LLM and the rest
|
||||
local top_file="tmp/changelog_top"
|
||||
local rest_file="tmp/changelog_rest"
|
||||
head -n "$num_lines" CHANGELOG.md > "$top_file"
|
||||
tail -n +"$((num_lines + 1))" CHANGELOG.md > "$rest_file"
|
||||
|
||||
# Create prompt file
|
||||
local prompt_file="tmp/llm_changelog_update"
|
||||
local prompt_file="tmp/llm_prompt"
|
||||
echo -e "\nWrite prompt to $prompt_file."
|
||||
cat << EOF > "$prompt_file"
|
||||
Update a CHANGELOG.md file based on the git diff provided.
|
||||
Update the top portion of a CHANGELOG.md file based on the git diff provided.
|
||||
|
||||
Below is only the first $num_lines line(s) of CHANGELOG.md, not the whole file. The remainder of the file is not shown and must not be referenced or reproduced.
|
||||
|
||||
Follow these instructions:
|
||||
1. Read the existing CHANGELOG.md content below
|
||||
1. Read the provided CHANGELOG.md excerpt below
|
||||
2. Analyze the git diff to understand what changes were made
|
||||
3. Update the CHANGELOG.md to include these changes in the appropriate section
|
||||
4. Follow the Keep a Changelog format (https://keepachangelog.com/en/1.1.0/)
|
||||
6. Maintain the existing format and structure of the CHANGELOG.md
|
||||
3. Update the excerpt to include these changes in the appropriate section (e.g. add an "Unreleased" entry, or a new version section, following Keep a Changelog format: https://keepachangelog.com/en/1.1.0/)
|
||||
4. Maintain the existing formatting and structure of the excerpt
|
||||
5. Do not truncate or omit any part of the excerpt that doesn't need to change
|
||||
|
||||
Reply with the complete updated CHANGELOG.md content only, in the exact same format as provided.
|
||||
Reply with the complete updated excerpt only, in the exact same format as provided, and nothing else (no preamble, no explanation, no code fences).
|
||||
|
||||
<<<CHANGELOG.md>>>
|
||||
$(cat CHANGELOG.md )
|
||||
<<<CHANGELOG.md (top $num_lines lines)>>>
|
||||
$(cat "$top_file")
|
||||
|
||||
<<<git diff --staged>>>
|
||||
$(git diff --staged)
|
||||
@@ -40,7 +50,7 @@ $(git diff --staged)
|
||||
EOF
|
||||
|
||||
# Run the llm command
|
||||
echo -e "Send prompt with CHANGELOG.md and git diff to LLM and wait for response."
|
||||
echo -e "Send prompt with CHANGELOG.md excerpt and git diff to LLM and wait for response."
|
||||
local result=$(cat "$prompt_file" | llm)
|
||||
|
||||
# Check if result is empty
|
||||
@@ -50,7 +60,7 @@ EOF
|
||||
fi
|
||||
|
||||
# Save the result to a file
|
||||
local result_file="tmp/llm_changelog_result"
|
||||
local result_file="tmp/llm_prompt_result"
|
||||
echo "$result" > "$result_file"
|
||||
echo -e "Saved response to $result_file.\n"
|
||||
|
||||
@@ -63,8 +73,9 @@ EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Update CHANGELOG.md
|
||||
cp "$result_file" CHANGELOG.md
|
||||
# Update CHANGELOG.md: new top + untouched rest
|
||||
cat "$result_file" "$rest_file" > tmp/changelog_new
|
||||
cp tmp/changelog_new CHANGELOG.md
|
||||
echo "CHANGELOG.md has been updated."
|
||||
|
||||
# Stage the updated CHANGELOG.md
|
||||
@@ -77,4 +88,4 @@ EOF
|
||||
}
|
||||
ucwl() {
|
||||
update-changelog-with-llm "$@"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user