Files
gartenmanager/.claude/scripts/git-pr.sh
Faultier314 5b00036951 docs: update CLAUDE.md and add git helper scripts
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-06 07:56:33 +02:00

62 lines
1.9 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.
#!/usr/bin/env bash
# git-pr.sh Pull-Request via Gitea API erstellen und optional mergen
#
# Verwendung:
# bash .claude/scripts/git-pr.sh create <head> <base> "<title>" ["<body>"]
# bash .claude/scripts/git-pr.sh merge <pr_number> [squash|merge|rebase]
# bash .claude/scripts/git-pr.sh list [open|closed]
set -euo pipefail
REPO="Admin/gartenmanager"
API="https://tea.jr-family.de/api/v1"
get_token() {
git credential fill <<'EOF' | grep "^password=" | cut -d= -f2-
protocol=https
host=tea.jr-family.de
EOF
}
CMD="${1:-}"
case "$CMD" in
create)
HEAD="${2:?'head branch fehlt'}"
BASE="${3:?'base branch fehlt'}"
TITLE="${4:?'titel fehlt'}"
BODY="${5:-}"
TOKEN=$(get_token)
RESULT=$(curl -s -X POST "$API/repos/$REPO/pulls" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"head\":\"$HEAD\",\"base\":\"$BASE\",\"title\":\"$TITLE\",\"body\":\"$BODY\"}")
PR_NUM=$(echo "$RESULT" | python3 -c "import sys,json; r=json.load(sys.stdin); print(r.get('number','ERR: '+str(r.get('message',''))))")
echo "PR #$PR_NUM erstellt: $TITLE ($HEAD$BASE)"
;;
merge)
PR_NUM="${2:?'PR-Nummer fehlt'}"
STYLE="${3:-squash}"
TOKEN=$(get_token)
curl -s -X POST "$API/repos/$REPO/pulls/$PR_NUM/merge" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"Do\":\"$STYLE\"}"
echo "PR #$PR_NUM gemergt ($STYLE)"
;;
list)
STATE="${2:-open}"
TOKEN=$(get_token)
curl -s "$API/repos/$REPO/pulls?state=$STATE&limit=20" \
-H "Authorization: Bearer $TOKEN" | \
python3 -c "import sys,json; [print(f\"#{r['number']} [{r['state']}] {r['title']} ({r['head']['label']} → {r['base']['label']})\") for r in json.load(sys.stdin)]"
;;
*)
echo "Verwendung: bash .claude/scripts/git-pr.sh [create|merge|list] ..."
exit 1
;;
esac