From 5a5a2498c0492e3f46da0c312424377b2a45bd79 Mon Sep 17 00:00:00 2001 From: lyn Date: Mon, 13 Apr 2026 10:16:52 +0000 Subject: [PATCH] Add list-projs script --- git-hangman-lab/scripts/list-projs | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 git-hangman-lab/scripts/list-projs diff --git a/git-hangman-lab/scripts/list-projs b/git-hangman-lab/scripts/list-projs new file mode 100755 index 0000000..8d2ed5f --- /dev/null +++ b/git-hangman-lab/scripts/list-projs @@ -0,0 +1,43 @@ +#!/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 + +# List all repos the user has access to (owned + collaborated) +repos=$(curl -s -u "$USER:$TOKEN" "$GIT_BASE/user/repos?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) | | | |" \ No newline at end of file