Skip to content

Instantly share code, notes, and snippets.

@konsalex
Last active June 20, 2024 02:40
Show Gist options
  • Save konsalex/bf6a2365416e34a8745cc31af9a2611f to your computer and use it in GitHub Desktop.
Save konsalex/bf6a2365416e34a8745cc31af9a2611f to your computer and use it in GitHub Desktop.
Generate a commit message based on a changeset file πŸ¦‹ using ollama πŸ¦™
#!/bin/bash
file=$(find ./.changeset/ -type f -name '*.md' | grep -E '^[./a-z-]+\.md$')
prompt_template=$(cat <<-END
You are a programmer, trained to write commit messages.
You follow the Conventional Commits specification.
feat: for new features
chore: for maintenance work
fix: for bug fixes
Below, you will receive a changeset, which is a list of changes to the codebase.
Based on this information generate a commit message.
Example changeset:
'''
---
"@neo4j-ndl/base": minor
---
added a boolean variable to the button to control disabled states and modify styles
'''
Example commit message: 'feat: added new disabled boolean variable to button'
Return the commit message as a json response.
THE RESULT SHOULD ONLY BE A VALID JSON!
Example response:
{
"commit": "feat: added new disabled boolean variable to button"
}
Keep the generated commit message strictly under 50 characters, if its more summarise it.
THE COMMIT MESSAGE SHOULD NOT BE MORE THAN 50 CHARACTERS!!!!!
Do not mention the name of the package (in the example @neo4j-ndl/base),
and do not include any other information/text rather than the commit message itself.
Changeset:\n
END
)
prompt_template+="$(cat $file)"
# Write response to test.json for testing
#http POST http://localhost:11434/api/generate model=codellama prompt="$prompt_template" stream:=false | jq .response > test.json
commit_message=$(http POST http://localhost:11434/api/generate options:='{"seed": 42, "temperature": 0.9}' model=llama2:13b-chat prompt="$prompt_template" stream:=false | jq .response)
# Parsefro JSON response
commit_clean=$(jq "fromjson | .commit" <<< $commit_message)
echo "πŸ€– Your commit message:"
echo "$commit_clean"
printf "\n\nπŸ“Ž Commit message copied to clipboard"
echo "$commit_clean" | pbcopy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment