fix sync bugs

This commit is contained in:
2026-08-19 08:25:30 +03:00
parent a752daff3d
commit 5c3b3414ee
Regular → Executable
+20 -2
View File
@@ -7,7 +7,11 @@ GITHUB_TOKEN="${GITHUB_TOKEN:?Set GITHUB_TOKEN env var (PAT with repo read acces
GITEA_URL="${GITEA_URL:?Set GITEA_URL env var, e.g. https://gitea.andwati.com}"
GITEA_TOKEN="${GITEA_TOKEN:?Set GITEA_TOKEN env var (Gitea access token, repo scope)}"
GITEA_OWNER="${GITEA_OWNER:-andwati}"
GITEA_URL="${GITEA_URL%/}" # a trailing slash yields //api/v1/... which some proxies mangle
MIRROR_INTERVAL="${MIRROR_INTERVAL:-8h0m0s}"
# Optional: process a single repo instead of all of them, e.g. ONLY=blog ./mirror-github-to-gitea.sh
# Useful for smoke-testing one repo before turning the script loose on the whole account.
ONLY="${ONLY:-}"
# --- Fetch all repos for the GitHub user (paginated), including private ones ---
# Uses /user/repos (authenticated, sees private repos owned by the token's user)
@@ -25,11 +29,20 @@ done
total=$(echo "$repos_json" | jq 'length')
echo "Found ${total} repos on GitHub for ${GITHUB_USER}"
if [ -n "$ONLY" ]; then
echo "ONLY=${ONLY} set - skipping every other repo."
fi
matched=0
while read -r entry; do
name=$(echo "$entry" | jq -r '.name')
private=$(echo "$entry" | jq -r '.private')
if [ -n "$ONLY" ] && [ "$name" != "$ONLY" ]; then
continue
fi
matched=$((matched + 1))
echo "Processing: ${name} (private=${private})"
# Check if it already exists in Gitea
@@ -54,7 +67,7 @@ while read -r entry; do
echo " Visibility updated to private=${private}."
else
echo " Failed to update visibility (HTTP ${patch_code}):"
cat /tmp/gitea_patch_resp.json
cat /tmp/gitea_patch_resp.json; echo
fi
else
echo " Already mirrored, visibility already matches (private=${gitea_private}). Skipping."
@@ -90,10 +103,15 @@ while read -r entry; do
echo " Created mirror (private=${private})."
else
echo " Failed (HTTP ${http_code}):"
cat /tmp/gitea_migrate_resp.json
cat /tmp/gitea_migrate_resp.json; echo
fi
sleep 1 # be gentle on both APIs
done < <(echo "$repos_json" | jq -c '.[] | {name, private}')
if [ -n "$ONLY" ] && [ "$matched" -eq 0 ]; then
echo "No repo named '${ONLY}' found among the ${total} repos on GitHub. Nothing done."
exit 1
fi
echo "Done."