#!/usr/bin/env bash # Fetch a PR's diff and metadata for review. # # scripts/review.sh 7 # print the diff # scripts/review.sh 7 --meta # title, author, branch, CI state # # Requires GITEA_TOKEN. set -euo pipefail GITEA_URL="${GITEA_URL:-http://192.168.0.3:3000}" OWNER="${GITEA_OWNER:-BBergle}" REPO="${GITEA_REPO:-bike-app}" [ -n "${GITEA_TOKEN:-}" ] || { echo "error: GITEA_TOKEN not set" >&2; exit 1; } PR="${1:-}" [ -n "$PR" ] || { echo "usage: scripts/review.sh [--meta]" >&2; exit 1; } api() { curl -sS -H "Authorization: token $GITEA_TOKEN" "$GITEA_URL/api/v1/repos/$OWNER/$REPO/$1"; } if [ "${2:-}" = "--meta" ]; then api "pulls/$PR" | jq '{number, title, user: .user.login, head: .head.ref, base: .base.ref, mergeable, draft, additions, deletions, changed_files}' echo "--- commit status ---" SHA="$(api "pulls/$PR" | jq -r '.head.sha')" api "commits/$SHA/status" | jq '{state, statuses: [.statuses[]? | {context, state}]}' else api "pulls/$PR.diff" fi