From 5c3b3414ee2fb62f0249aacf33cb1425002e3514 Mon Sep 17 00:00:00 2001 From: andwati Date: Wed, 19 Aug 2026 08:25:30 +0300 Subject: [PATCH] fix sync bugs --- mirror-github-to-gitea.sh | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) mode change 100644 => 100755 mirror-github-to-gitea.sh diff --git a/mirror-github-to-gitea.sh b/mirror-github-to-gitea.sh old mode 100644 new mode 100755 index 3d24def..4a15c26 --- a/mirror-github-to-gitea.sh +++ b/mirror-github-to-gitea.sh @@ -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}') -echo "Done." \ No newline at end of file +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."