diff --git a/README.md b/README.md index 7b16eb1..3763dd2 100644 --- a/README.md +++ b/README.md @@ -616,3 +616,26 @@ Implementations of the task file standard can be accessed from these projects: - [Mint-System/Odoo-Wiki](https://github.com/Mint-Wiki/Odoo-Build/blob/main/task) - [Mint-System/Website](https://github.com/Mint-System/Website/blob/main/task) - [Mint-System/Wiki](https://github.com/Mint-System/Wiki/blob/main/task) + +## Library + +The repository of this website provides a library of reusable functions. + +Clone the repository into your home folder: + +```bash +cd ~ +git clone git@github.com:janikvonrotz/taskfile.build.git +``` + +In your task file you can import these functions from the tasfile library. + +### commit-with-llm + +```bash + printf "$COLUMN" "commit-with-llm" "" "Commit with llm generated commit message." + +# Import commands + +source ~/taskfile.build/bin/commit-with-llm +``` diff --git a/bin/commit-with-llm b/bin/commit-with-llm new file mode 100755 index 0000000..1b06ebc --- /dev/null +++ b/bin/commit-with-llm @@ -0,0 +1,38 @@ +function commit-with-llm() { + + mkdir -p tmp + PROMPT_FILE="tmp/llm_update" + echo -e "\nWrite prompt to $PROMPT_FILE." + cat << EOF > "$PROMPT_FILE" +Look at the git diff below and reply with a git commit message. Ensure that the commit message matches the conventional commits specification. +If possible add a scope. Reply with the commit message only. Format the message so it can be used with: git commit -m "\$RESULT" + +$(git diff --staged) +EOF + + # Run the llm command + echo -e "Send prompt with staged git diff and wait for the response of the $LLM_MODEL LLM." + RESULT=$(cat "$PROMPT_FILE" | llm -m "$LLM_MODEL") + + # Check if result is empty + if [ -z "$RESULT" ]; then + echo "No response from the model. Exiting." + exit 1 + fi + + # Save the result to a file + RESULT_FILE="tmp/llm_update_result" + echo "$RESULT" > "$RESULT_FILE" + echo -e "Saved response to $RESULT_FILE.\n" + + # Show a preview of result file + less "$RESULT_FILE" + + # Ask for confirmation before updating files + read -p "Do you want to commit with this message? (y/n): " CONFIRM + if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then + exit 0 + fi + + git commit -m "$RESULT" +} \ No newline at end of file