#!/bin/bash
# Gitea API helper script - ALWAYS uses HTTP (not HTTPS)

API_BASE="http://10.0.30.169:3000/api/v1"
REPO="ilia/nanobot"
TOKEN="${NANOBOT_GITLE_TOKEN}"

if [ -z "$TOKEN" ]; then
    echo "Error: NANOBOT_GITLE_TOKEN not set"
    exit 1
fi

case "$1" in
    prs|pulls)
        curl -s -H "Authorization: token $TOKEN" \
             "${API_BASE}/repos/${REPO}/pulls"
        ;;
    issues)
        curl -s -H "Authorization: token $TOKEN" \
             "${API_BASE}/repos/${REPO}/issues?state=${2:-open}"
        ;;
    *)
        echo "Usage: $0 {prs|pulls|issues} [state]"
        echo "Example: $0 prs"
        echo "Example: $0 issues open"
        exit 1
        ;;
esac
