generated from nhcarrigan/template
This commit is contained in:
57
products.sh
Executable file
57
products.sh
Executable file
@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set your Gitea instance base URL and API token
|
||||
GITEA_URL="https://git.nhcarrigan.com/api/v1"
|
||||
TOKEN=$GITEA_TOKEN # Pass as CLI arg
|
||||
|
||||
# Output file
|
||||
OUTPUT_FILE="./products/data.json"
|
||||
|
||||
# Organizations and their categories
|
||||
declare -A orgs=(
|
||||
["nhcarrigan"]="public"
|
||||
["nhcarrigan-games"]="games"
|
||||
["nhcarrigan-private"]="private"
|
||||
["nhcarrigan-archive"]="archived"
|
||||
)
|
||||
|
||||
# Initialize the JSON array
|
||||
echo "[" > "$OUTPUT_FILE"
|
||||
|
||||
first=true
|
||||
|
||||
for org in "${!orgs[@]}"; do
|
||||
category="${orgs[$org]}"
|
||||
echo "Fetching repos for $org..."
|
||||
|
||||
# Fetch repos from the API
|
||||
response=$(curl -s -H "Authorization: token $TOKEN" "$GITEA_URL/orgs/$org/repos")
|
||||
|
||||
# Parse each repo
|
||||
echo "$response" | jq -c '.[]' | while read -r repo; do
|
||||
name=$(echo "$repo" | jq -r '.name')
|
||||
description=$(echo "$repo" | jq -r '.description // ""')
|
||||
url=$(echo "$repo" | jq -r '.website')
|
||||
|
||||
# Skip ".profile" repos
|
||||
if [[ "$name" == ".profile" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# Add comma if not the first item
|
||||
if [ "$first" = true ]; then
|
||||
first=false
|
||||
else
|
||||
echo "," >> "$OUTPUT_FILE"
|
||||
fi
|
||||
|
||||
# Write the repo object to the file
|
||||
jq -n --arg name "$name" --arg description "$description" --arg url "$url" --arg category "$category" \
|
||||
'{name: $name, description: $description, url: $url, category: $category}' >> "$OUTPUT_FILE"
|
||||
done
|
||||
done
|
||||
|
||||
# Close the JSON array
|
||||
echo "]" >> "$OUTPUT_FILE"
|
||||
|
||||
echo "✨ Done! Your product data is in $OUTPUT_FILE 💖"
|
Reference in New Issue
Block a user