Files
agents/pr_review.sh
2026-03-21 14:24:10 +01:00

61 lines
1.6 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
set -euo pipefail
usage() {
printf "Usage: %s [-s|--source <branch>] [-t|--target <branch>] [source target] (target defaults to 'main')\n" "$0"
exit 2
}
source_branch=""
# default target branch to main
target_branch="main"
# Parse options: -s|--source and -t|--target. Falls back to positional args.
while [[ $# -gt 0 ]]; do
case "$1" in
-s|--source)
source_branch="$2"; shift 2;;
-t|--target)
target_branch="$2"; shift 2;;
-h|--help)
usage;;
--)
shift; break;;
-*)
printf "Unknown option: %s\n" "$1"; usage;;
*)
if [[ -z "$source_branch" ]]; then
source_branch="$1"
elif [[ -z "$target_branch" ]]; then
target_branch="$1"
fi
shift;;
esac
done
if [[ -z "$source_branch" ]]; then
printf "no source branch specified, using current HEAD\n"
source_branch="HEAD"
else
printf "checking out source branch: %s\n" "$source_branch"
git checkout "$source_branch"
fi
# Run unit tests
printf "\nUnit test results:\n´´´bash\n"
python3 -m unittest discover
printf "´´´\n"
# Get list of changed files between source and target branches
export CHANGED_FILES=$(git diff --name-only "$source_branch" "$target_branch")
for file in $CHANGED_FILES; do
if [ -f "${file}" ]; then
printf "\nHere is the diff between source (%s) version of %s and target (%s):\n\n" "$source_branch" "$file" "$target_branch"
printf "´´´diff\n"
git --no-pager diff -U1000 -W "$target_branch" -- "$file"
printf "´´´\n"
fi
done
# adjust model context length if needed