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" \
|
RESP=$(curl -s -H "Authorization: token $TOKEN" \
|
||||||
"https://git.hangman-lab.top/api/v1/repos/search?q=${REPO_NAME}")
|
"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
|
import sys, json
|
||||||
data = json.load(sys.stdin)
|
data = json.load(sys.stdin)
|
||||||
results = data.get('data', []) if isinstance(data, dict) else []
|
results = data.get('data', []) if isinstance(data, dict) else []
|
||||||
ok = True
|
|
||||||
matches = []
|
|
||||||
for r in results:
|
for r in results:
|
||||||
if isinstance(r, dict) and r.get('name') == '${REPO_NAME}':
|
if isinstance(r, dict) and r.get('name') == '${REPO_NAME}':
|
||||||
owner = r.get('owner', {})
|
owner = r.get('owner', {})
|
||||||
if isinstance(owner, dict):
|
login = owner.get('login', '') if isinstance(owner, dict) else ''
|
||||||
login = owner.get('login', '')
|
out = {
|
||||||
else:
|
'name': r.get('name', ''),
|
||||||
login = ''
|
|
||||||
matches.append({
|
|
||||||
'id': r.get('id'),
|
'id': r.get('id'),
|
||||||
'owner': {'login': login},
|
'owner': login,
|
||||||
'name': r.get('name'),
|
'clone-url': r.get('clone_url', '')
|
||||||
'clone_url': r.get('clone_url', '')
|
}
|
||||||
})
|
print(json.dumps(out))
|
||||||
print(json.dumps({'ok': ok, 'data': matches}))
|
sys.exit(0)
|
||||||
" 2>/dev/null; then
|
print('NOT_FOUND')
|
||||||
echo '{"ok": false, "data": []}'
|
" 2>/dev/null)
|
||||||
exit 0
|
|
||||||
|
if [[ "$RESULT" == "NOT_FOUND" ]]; then
|
||||||
|
echo "Error: repository '$REPO_NAME' not found" >&2
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "$RESULT"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ─────────────────────────────────────────────
|
# ─────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user