Files
skills/skills/gitea-tea/scripts/tea-pr-review.sh
2026-06-06 15:01:43 +02:00

109 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/tea-common.sh"
usage() {
cat <<'EOF'
Review or merge a Gitea pull request.
Usage:
tea-pr-review.sh approve INDEX [--body TEXT | --body-file FILE]
tea-pr-review.sh reject INDEX [--body TEXT | --body-file FILE]
tea-pr-review.sh comment INDEX [--body TEXT | --body-file FILE]
tea-pr-review.sh merge INDEX [--style merge|rebase|squash|rebase-merge] [--title TITLE] [--message MESSAGE]
EOF
tea_usage_context
}
action="${1:-}"
if [[ "$action" == "--help" || "$action" == "-h" ]]; then
usage
exit 0
fi
[[ -n "$action" ]] || { usage >&2; exit 2; }
shift || true
index=""
body=""
body_file=""
style=""
title=""
message=""
while [[ $# -gt 0 ]]; do
case "$1" in
--body|-b) body=${2:?}; shift 2 ;;
--body-file|-F) body_file=${2:?}; shift 2 ;;
--style|-s) style=${2:?}; shift 2 ;;
--title|-t) title=${2:?}; shift 2 ;;
--message|-m) message=${2:?}; shift 2 ;;
--repo|-r) TEA_REPO=${2:?}; shift 2 ;;
--login|-l) TEA_LOGIN=${2:?}; shift 2 ;;
--remote|-R) TEA_REMOTE=${2:?}; shift 2 ;;
--help|-h) usage; exit 0 ;;
*)
if [[ -z "$index" ]]; then
index=$1
shift
else
echo "error: unknown argument: $1" >&2
usage >&2
exit 2
fi
;;
esac
done
tea_require
[[ -n "$index" ]] || { echo "error: INDEX is required" >&2; exit 2; }
[[ -z "$body" || -z "$body_file" ]] || { echo "error: use --body or --body-file, not both" >&2; exit 2; }
args=()
case "$action" in
approve)
comment="$(tea_read_optional_body "$body" "$body_file")"
args=(pull approve)
;;
reject)
reason="$(tea_read_body "$body" "$body_file")"
[[ -n "$reason" ]] || { echo "error: reject requires --body, --body-file, or stdin" >&2; exit 2; }
args=(pull reject)
;;
comment)
comment="$(tea_read_body "$body" "$body_file")"
[[ -n "$comment" ]] || { echo "error: comment requires --body, --body-file, or stdin" >&2; exit 2; }
args=(comment)
;;
merge)
args=(pull merge)
[[ -n "$style" ]] && args+=(--style "$style")
[[ -n "$title" ]] && args+=(--title "$title")
[[ -n "$message" ]] && args+=(--message "$message")
;;
*)
echo "error: action must be approve, reject, comment, or merge" >&2
usage >&2
exit 2
;;
esac
tea_append_context_args args
case "$action" in
approve)
args+=("$index")
[[ -n "$comment" ]] && args+=("$comment")
;;
reject)
args+=("$index" "$reason")
;;
comment)
args+=("$index" "$comment")
;;
merge)
args+=("$index")
;;
esac
exec tea "${args[@]}"