Files
macos-configuration/clone-resoftware-repos.fish
Trevi Awater b43937b395 updates
2026-03-08 08:54:14 +01:00

71 lines
1.7 KiB
Fish
Executable File

#!/usr/bin/env fish
set base_dir ~/Repositories
set org resoftware
set cloned 0
set skipped 0
set warnings 0
echo "Fetching repositories and custom properties for $org..."
set json (gh api "orgs/$org/properties/values" --paginate)
if test $status -ne 0
echo "Error: Failed to fetch repository properties from GitHub."
exit 1
end
set repo_lines (echo $json | python3 -c "
import json, sys
data = json.load(sys.stdin)
for repo in data:
name = repo['repository_name']
full_name = repo['repository_full_name']
customer = ''
for prop in repo.get('properties', []):
if prop['property_name'] == 'customer-number':
customer = prop.get('value', '') or ''
break
print(f'{name}\t{full_name}\t{customer}')
")
if test $status -ne 0
echo "Error: Failed to parse repository data."
exit 1
end
for line in $repo_lines
set parts (string split \t $line)
set repo_name $parts[1]
set full_name $parts[2]
set customer $parts[3]
if test -z "$customer"
echo "Warning: $full_name has no customer-number property, skipping."
set warnings (math $warnings + 1)
continue
end
set target_dir "$base_dir/$customer/$repo_name"
if test -d "$target_dir"
echo "Skipping $full_name (already exists at $target_dir)"
set skipped (math $skipped + 1)
continue
end
echo "Cloning $full_name into $target_dir..."
mkdir -p (dirname "$target_dir")
git clone "git@github.com:$full_name.git" "$target_dir"
if test $status -eq 0
set cloned (math $cloned + 1)
else
echo "Error: Failed to clone $full_name"
end
end
echo ""
echo "Done! Cloned: $cloned, Skipped: $skipped, Warnings: $warnings"