fix(git-hangman-lab): repo search - output single match as {"name","id","owner","clone-url"}, exit 1 if not found
This commit is contained in:
@@ -316,30 +316,31 @@ do_search() {
|
||||
RESP=$(curl -s -H "Authorization: token $TOKEN" \
|
||||
"https://git.hangman-lab.top/api/v1/repos/search?q=${REPO_NAME}")
|
||||
|
||||
if ! echo "$RESP" | python3 -c "
|
||||
RESULT=$(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({
|
||||
login = owner.get('login', '') if isinstance(owner, dict) else ''
|
||||
out = {
|
||||
'name': r.get('name', ''),
|
||||
'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
|
||||
'owner': login,
|
||||
'clone-url': r.get('clone_url', '')
|
||||
}
|
||||
print(json.dumps(out))
|
||||
sys.exit(0)
|
||||
print('NOT_FOUND')
|
||||
" 2>/dev/null)
|
||||
|
||||
if [[ "$RESULT" == "NOT_FOUND" ]]; then
|
||||
echo "Error: repository '$REPO_NAME' not found" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "$RESULT"
|
||||
}
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user