refactor(git-hangman-lab): get-latest now uses search API instead of list-all parsing

Replace fragile list-all + awk URL extraction with repo search command
for repo URL lookup. search returns {name,id,owner,clone-url} with
exact match, eliminating column-index dependency.
This commit is contained in:
2026-04-14 22:01:34 +00:00
parent 597282cbd7
commit 82e287b265

View File

@@ -273,13 +273,26 @@ do_get_latest() {
echo "Done: $REPO_DIR updated." echo "Done: $REPO_DIR updated."
else else
# Repo does not exist locally — clone it # Repo does not exist locally — search via API then clone
echo "Repo not found locally. Looking up URL..." echo "Repo not found locally. Searching..."
local search_result=""
search_result=$(bash "$SCRIPT_DIR/repo" search "$REPO_NAME" 2>&1)
local search_exit=$?
if [[ $search_exit -ne 0 ]]; then
echo "Error: repository '$REPO_NAME' not found"
exit 1
fi
local url="" local url=""
url=$(bash "$SCRIPT_DIR/repo" list-all 2>/dev/null | grep "| $REPO_NAME |" | awk -F'\\|' '{gsub(/^ +| +$/,"",$4); print $4}') url=$(echo "$search_result" | python3 -c "
import sys, json
data = json.load(sys.stdin)
print(data.get('clone-url', ''))
" 2>/dev/null)
if [[ -z "$url" ]]; then if [[ -z "$url" ]]; then
echo "Error: repository '$REPO_NAME' not found in list-all output" echo "Error: failed to parse clone URL for '$REPO_NAME'"
exit 1 exit 1
fi fi