diff --git a/git-hangman-lab/scripts/repo b/git-hangman-lab/scripts/repo index 09fcfe9..c8c56d0 100755 --- a/git-hangman-lab/scripts/repo +++ b/git-hangman-lab/scripts/repo @@ -273,13 +273,26 @@ do_get_latest() { echo "Done: $REPO_DIR updated." else - # Repo does not exist locally — clone it - echo "Repo not found locally. Looking up URL..." + # Repo does not exist locally — search via API then clone + 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="" - 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 - echo "Error: repository '$REPO_NAME' not found in list-all output" + echo "Error: failed to parse clone URL for '$REPO_NAME'" exit 1 fi