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.
This commit is contained in:
@@ -300,11 +300,53 @@ do_get_latest() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ─────────────────────────────────────────────
|
||||||
|
# search
|
||||||
|
# ─────────────────────────────────────────────
|
||||||
|
do_search() {
|
||||||
|
if [[ $# -lt 1 ]]; then
|
||||||
|
echo "Usage: $0 search <exact-repo-name>"
|
||||||
|
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
|
# Dispatch
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
if [[ $# -lt 1 ]]; then
|
if [[ $# -lt 1 ]]; then
|
||||||
echo "Usage: $0 <create|add-collaborators|list-all|config> [args...]"
|
echo "Usage: $0 <create|add-collaborators|list-all|config|search> [args...]"
|
||||||
echo ""
|
echo ""
|
||||||
echo "Commands:"
|
echo "Commands:"
|
||||||
echo " create <repo-name> Create a new repository"
|
echo " create <repo-name> Create a new repository"
|
||||||
@@ -312,6 +354,7 @@ if [[ $# -lt 1 ]]; then
|
|||||||
echo " list-all List all visible repositories"
|
echo " list-all List all visible repositories"
|
||||||
echo " config --repo-path <path> [--recursive] Configure repo credentials"
|
echo " config --repo-path <path> [--recursive] Configure repo credentials"
|
||||||
echo " get-latest <repo-name> [branch] [--recursive] [--force] Pull latest or clone if missing"
|
echo " get-latest <repo-name> [branch] [--recursive] [--force] Pull latest or clone if missing"
|
||||||
|
echo " search <exact-repo-name> Search for a repository by exact name"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -323,5 +366,6 @@ case "$subcommand" in
|
|||||||
list-all) do_list_all "$@" ;;
|
list-all) do_list_all "$@" ;;
|
||||||
config) do_config "$@" ;;
|
config) do_config "$@" ;;
|
||||||
get-latest) do_get_latest "$@" ;;
|
get-latest) do_get_latest "$@" ;;
|
||||||
|
search) do_search "$@" ;;
|
||||||
*) echo "Unknown command: $subcommand"; exit 1 ;;
|
*) echo "Unknown command: $subcommand"; exit 1 ;;
|
||||||
esac
|
esac
|
||||||
Reference in New Issue
Block a user