set -euo pipefail
APP_URL="${1:-http://localhost:3080}"
read -r -a NUGITEA <<< "${NUGITEA:-docker compose exec -T app nugitea}"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
seed_org() {
local path="$1"
if "${NUGITEA[@]}" org list | grep -qx "$path"; then
echo "skip org $path (already exists)"
return
fi
"${NUGITEA[@]}" org create "$path"
}
seed_repo() {
local path="$1" file="$2" content="$3"
if "${NUGITEA[@]}" repo list | grep -qx "$path"; then
echo "skip $path (already exists)"
return
fi
"${NUGITEA[@]}" repo create "$path"
local work="$tmp/${path//\//_}"
git init -q -b main "$work"
printf '%s\n' "$content" > "$work/$file"
git -C "$work" -c user.name=nugitea -c user.email=nugitea@localhost add "$file"
git -C "$work" -c user.name=nugitea -c user.email=nugitea@localhost commit -q -m "Initial commit"
git -C "$work" push -q "$APP_URL/$path.git" main
echo "seeded $path"
}
seed_org demo
seed_org demo/tools
seed_repo demo/foobar hello.txt "hello"
seed_repo demo/tools/barbaz sup.txt "sup"