#!/bin/bash # Forgejo CLI helper - token-efficient output set -e FORGEJO_URL="https://git.cloonar.com" FORGEJO_IP="10.42.97.55" TOKEN="03e35afac87cd3d8db7d4a186714dacf584c01f7" # Resolve git.cloonar.com to internal IP CURL="curl -sk --resolve git.cloonar.com:443:${FORGEJO_IP} -H \"Authorization: token ${TOKEN}\"" usage() { cat < [args] Commands: repos [org] List repos (optionally filter by org) files [path] List files in repo (default: root) cat Get file content issues List open issues prs List open pull requests branches List branches commits [n] Recent commits (default: 10) search Search repos raw Raw API call (e.g., /api/v1/user) EOF } case "${1:-}" in repos) if [ -n "${2:-}" ]; then eval $CURL "${FORGEJO_URL}/api/v1/orgs/$2/repos" | grep -oP '"full_name":"\K[^"]+' else eval $CURL "${FORGEJO_URL}/api/v1/user/repos?limit=50" | grep -oP '"full_name":"\K[^"]+' fi ;; files) [ -z "${2:-}" ] && { echo "Usage: forgejo files [path]"; exit 1; } path="${3:-.}" eval $CURL "${FORGEJO_URL}/api/v1/repos/$2/contents/${path}" | \ grep -oP '("name":"\K[^"]+|"type":"\K[^"]+)' | paste - - | awk '{print $2 "\t" $1}' ;; cat) [ -z "${3:-}" ] && { echo "Usage: forgejo cat "; exit 1; } eval $CURL "${FORGEJO_URL}/api/v1/repos/$2/contents/$3" | \ grep -oP '"content":"\K[^"]+' | base64 -d ;; issues) [ -z "${2:-}" ] && { echo "Usage: forgejo issues "; exit 1; } eval $CURL "${FORGEJO_URL}/api/v1/repos/$2/issues?state=open" | \ grep -oP '("number":\K\d+|"title":"\K[^"]+)' | paste - - | awk '{print "#" $1 " " $2}' ;; prs) [ -z "${2:-}" ] && { echo "Usage: forgejo prs "; exit 1; } eval $CURL "${FORGEJO_URL}/api/v1/repos/$2/pulls?state=open" | \ grep -oP '("number":\K\d+|"title":"\K[^"]+)' | paste - - | awk '{print "#" $1 " " $2}' ;; branches) [ -z "${2:-}" ] && { echo "Usage: forgejo branches "; exit 1; } eval $CURL "${FORGEJO_URL}/api/v1/repos/$2/branches" | grep -oP '"name":"\K[^"]+' ;; commits) [ -z "${2:-}" ] && { echo "Usage: forgejo commits [n]"; exit 1; } limit="${3:-10}" eval $CURL "${FORGEJO_URL}/api/v1/repos/$2/commits?limit=${limit}" | \ grep -oP '("sha":"\K[^"]{7}|"message":"\K[^"]+)' | paste - - | head -${limit} ;; search) [ -z "${2:-}" ] && { echo "Usage: forgejo search "; exit 1; } eval $CURL "${FORGEJO_URL}/api/v1/repos/search?q=$2" | grep -oP '"full_name":"\K[^"]+' ;; raw) [ -z "${2:-}" ] && { echo "Usage: forgejo raw "; exit 1; } eval $CURL "${FORGEJO_URL}$2" ;; *) usage ;; esac