Skip to content

Instantly share code, notes, and snippets.

@drikusroor
Last active April 25, 2023 10:40
Show Gist options
  • Save drikusroor/0c9249b1393306fbce46458a99e9e04f to your computer and use it in GitHub Desktop.
Save drikusroor/0c9249b1393306fbce46458a99e9e04f to your computer and use it in GitHub Desktop.
ChatGPT prompt generation script to help me with Pull / Merge Requests
#!/bin/bash
# This script will help you to generate a ChatGPT prompt that you can use to summarize and review the changes between two branches.
# It will prompt you for the feature branch, the branch to compare to, the ticket/story/bug description, and any additional feedback.
# It will then output the changes and the prompt to a file called summareview.txt.
function usage {
echo -e "\033[1mUsage:\033[0m $0 [-h | --help] [-o output_file] [-p]"
echo ""
echo -e "\033[1mOptions:\033[0m"
echo -e " \033[32m-h, --help\033[0m Show this help message and exit"
echo -e " \033[32m-o, --output <file>\033[0m Save the summary and review prompt to the specified file"
echo -e " \033[32m-p, --print\033[0m Print the summary and review prompt to the console"
echo ""
echo "If neither -o nor -p is provided, the user will be prompted to choose either to output to a file (default: summareview.txt) or to the console."
}
output_option=""
print_option=false
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-h | --help)
usage
exit 0
;;
-o | --output)
output_option="$2"
shift
shift
;;
-p | --print)
print_option=true
shift
;;
*)
echo "Unknown option: $1"
echo ""
usage
exit 1
;;
esac
done
# Get the current branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
# Prompt for feature branch (default: current branch)
read -p "Enter the feature branch to compare (default: $current_branch): " feature_branch
feature_branch=${feature_branch:-$current_branch}
# Prompt for branch to compare to (default: develop)
read -p "Enter the branch to compare to (default: develop): " compare_branch
compare_branch=${compare_branch:-develop}
# Prompt for ticket/story/bug description
read -p "Enter the ticket/story/bug description: " ticket_description
# Prompt for additional feedback
read -p "Enter any additional feedback (optional): " additional_feedback
# Execute git log command and store the output in a variable
git_log_output=$(git log $compare_branch..$feature_branch --oneline)
# Execute git diff command and store the output in a variable
git_diff_files_output=$(git diff --name-status $compare_branch..$feature_branch -- . ':(exclude)./**/package-lock.json' ':(exclude)./**/composer.lock')
# Add an exclusion for snapshot files (filenames ending in .snap)
git_diff__lines_output=$(git diff $compare_branch..$feature_branch -- . ':(exclude)./**/package-lock.json' ':(exclude)./**/composer.lock' ':(exclude)./**/*.snap')
# Add ChatGPT prompt
prompt="
Below are the changes between $feature_branch and $compare_branch branches.
Ticket/Story/Bug Description:
$ticket_description
Additional Feedback:
$additional_feedback
Please summarize and review the changes like below in a markdown code block (using backticks!):
\\\`\\\`\\\`md
## 1. Summary (1-2 paragraphs)
Lorem ispum dolor sit amet, consectetur adipiscing elit.
## 2. Changed files
- file1.php
- file2.php
- file3.php
## 3. ChatGPT review of changes and advice for improvement (1-2 paragraphs)
Lorem ispum dolor sit amet, consectetur adipiscing elit.
\\\`\\\`\\\`
"
if [ -z "$output
_option" ] && ! $print_option; then
read -p "Do you want to output the prompt to a file [F] or to the terminal [T]? (default: F): " output_choice
output_choice=${output_choice:-F}
if [ "$output_choice" == "F" ] || [ "$output_choice" == "f" ]; then
output_option="summareview.txt"
else
print_option=true
fi
fi
if [ -n "$output_option" ]; then
{
echo "$prompt"
echo "================="
echo "Git Log Output:"
echo "$git_log_output"
echo ""
echo "Git Diff Files Output:"
echo "$git_diff_files_output"
echo ""
echo "Git Diff Lines Output:"
echo "$git_diff__lines_output"
echo "================="
} >"$output_option"
echo "Changes have been saved to $output_option."
elif $print_option; then
echo "$prompt"
echo "================="
echo "Git Log Output:"
echo "$git_log_output"
echo ""
echo "Git Diff Files Output:"
echo "$git_diff_files_output"
echo ""
echo "Git Diff Lines Output:"
echo "$git_diff__lines_output"
echo "================="
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment