#!/usr/bin/env bash set -euo pipefail GIT_BASE="https://git.hangman-lab.top/api/v1" USER="$(secret-mgr get-username --key git)" TOKEN="$(secret-mgr get-secret --key git)" if [[ -z "$USER" || -z "$TOKEN" ]]; then echo "Error: missing git credentials from secret-mgr" >&2 exit 1 fi # Fetch all visible repos (owned + collaborated + public) repos=$(curl -s -u "$USER:$TOKEN" "$GIT_BASE/user/repos?type=all&per_page=100" 2>/dev/null) if [[ -z "$repos" ]]; then echo "| proj-name | owner | url | can-write |" echo "|------------|-------|-----|-----------|" exit 0 fi echo "| proj-name | owner | url | can-write |" echo "|------------|-------|-----|-----------|" echo "$repos" | python3 -c " import sys, json try: data = json.load(sys.stdin) if not isinstance(data, list): data = [data] except: print('Error parsing response') sys.exit(1) for r in data: name = r.get('name', '') owner = r.get('owner', {}).get('login', '') url = r.get('html_url', '') can_write = 'yes' if r.get('permissions', {}).get('push', False) else 'no' print(f'| {name} | {owner} | {url} | {can_write} |') " 2>/dev/null || echo "| (error parsing repos) | | | |"