ai-commit.sh 989 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. # Check for required Git configuration files
  3. if [ ! -f "$HOME/.gitconfig" ]; then
  4. >&2 echo "Error: Git configuration file not found at $HOME/.gitconfig"
  5. exit 1
  6. fi
  7. if [ ! -f "$HOME/.git-credentials" ]; then
  8. >&2 echo "Error: Git credentials file not found at $HOME/.git-credentials"
  9. exit 1
  10. fi
  11. # Determine which script to run and filter arguments
  12. script_to_run="/app/git_commit_ai.py"
  13. docker_args=()
  14. for arg in "$@"; do
  15. if [[ "$arg" == "-r" ]]; then
  16. script_to_run="/app/git_rebase_ai.py"
  17. elif [[ "$arg" == "-w" ]]; then
  18. script_to_run="/app/git_reword_ai.py"
  19. else
  20. docker_args+=("$arg")
  21. fi
  22. done
  23. docker run --rm -it \
  24. -v "$(pwd):/repo" \
  25. -v "$HOME/.gitconfig:/home/appuser/.gitconfig:ro" \
  26. -v "$HOME/.git-credentials:/home/appuser/.git-credentials:ro" \
  27. -e GEMINI_API_KEY="$GEMINI_API_KEY" \
  28. -e GEMINI_MODEL="${GEMINI_MODEL:-gemini-2.0-flash}" \
  29. -u "$(id -u):$(id -g)" \
  30. ${DOCKER_IMAGE_NAME:-docker.senomas.com/commit:1.0} "$script_to_run" ${docker_args[@]}