From 060b95f69973900bcf29775b555fa6dd5c8af18c Mon Sep 17 00:00:00 2001 From: orion Date: Tue, 14 Apr 2026 21:52:27 +0000 Subject: [PATCH] feat(git-hangman-lab): repo search - search repository by exact name Send GET to /api/v1/repos/search?q={name} and filter results by exact name match. Output: {"ok": true/false, "data": [...]} with each match containing id, owner.login, name, clone_url. --- git-hangman-lab/scripts/repo | 46 +++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/git-hangman-lab/scripts/repo b/git-hangman-lab/scripts/repo index 1e189d1..33071fa 100755 --- a/git-hangman-lab/scripts/repo +++ b/git-hangman-lab/scripts/repo @@ -300,11 +300,53 @@ do_get_latest() { fi } +# ───────────────────────────────────────────── +# search +# ───────────────────────────────────────────── +do_search() { + if [[ $# -lt 1 ]]; then + echo "Usage: $0 search " + exit 1 + fi + + REPO_NAME="$1" + + TOKEN=$(secret-mgr get-secret --key git-access-token 2>/dev/null || secret-mgr get-secret --key git) + + RESP=$(curl -s -H "Authorization: token $TOKEN" \ + "https://git.hangman-lab.top/api/v1/repos/search?q=${REPO_NAME}") + + if ! echo "$RESP" | python3 -c " +import sys, json +data = json.load(sys.stdin) +results = data.get('data', []) if isinstance(data, dict) else [] +ok = True +matches = [] +for r in results: + if isinstance(r, dict) and r.get('name') == '${REPO_NAME}': + owner = r.get('owner', {}) + if isinstance(owner, dict): + login = owner.get('login', '') + else: + login = '' + matches.append({ + 'id': r.get('id'), + 'owner': {'login': login}, + 'name': r.get('name'), + 'clone_url': r.get('clone_url', '') + }) +print(json.dumps({'ok': ok, 'data': matches})) +" 2>/dev/null; then + echo '{"ok": false, "data": []}' + exit 0 + fi +} + # ───────────────────────────────────────────── # Dispatch # ───────────────────────────────────────────── if [[ $# -lt 1 ]]; then - echo "Usage: $0 [args...]" + echo "Usage: $0 [args...]" echo "" echo "Commands:" echo " create Create a new repository" @@ -312,6 +354,7 @@ if [[ $# -lt 1 ]]; then echo " list-all List all visible repositories" echo " config --repo-path [--recursive] Configure repo credentials" echo " get-latest [branch] [--recursive] [--force] Pull latest or clone if missing" + echo " search Search for a repository by exact name" exit 1 fi @@ -323,5 +366,6 @@ case "$subcommand" in list-all) do_list_all "$@" ;; config) do_config "$@" ;; get-latest) do_get_latest "$@" ;; + search) do_search "$@" ;; *) echo "Unknown command: $subcommand"; exit 1 ;; esac \ No newline at end of file