From 1bdc15b258c5519fc41cd0655675f39ada0033a3 Mon Sep 17 00:00:00 2001 From: andwati Date: Tue, 18 Aug 2026 16:07:12 +0300 Subject: [PATCH] Add .gitignore and enhance Gitea mirror script for repo visibility updates --- .gitignore | 18 ++++++++++++++++++ mirror-github-to-gitea.sh | 24 ++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..be902fc --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# OS +.DS_Store +Thumbs.db + +# Editor +.vscode/ +.idea/ +*.swp +*.swo + +# Env / secrets — never commit real tokens +.env +.env.* +!.env.example + +# Logs / temp +*.log +/tmp/ \ No newline at end of file diff --git a/mirror-github-to-gitea.sh b/mirror-github-to-gitea.sh index 82bd6f6..231c988 100644 --- a/mirror-github-to-gitea.sh +++ b/mirror-github-to-gitea.sh @@ -33,12 +33,32 @@ echo "$repos_json" | jq -c '.[] | {name, private}' | while read -r entry; do echo "Processing: ${name} (private=${private})" # Check if it already exists in Gitea - existing_status=$(curl -s -o /dev/null -w "%{http_code}" \ + existing_resp=$(curl -s -w "\n%{http_code}" \ -H "Authorization: token ${GITEA_TOKEN}" \ "${GITEA_URL}/api/v1/repos/${GITEA_OWNER}/${name}") + existing_status=$(echo "$existing_resp" | tail -n1) + existing_body=$(echo "$existing_resp" | sed '$d') if [ "$existing_status" == "200" ]; then - echo " Already mirrored, skipping migration (existing mirror syncs on its own schedule)." + gitea_private=$(echo "$existing_body" | jq -r '.private') + + if [ "$gitea_private" != "$private" ]; then + echo " Already mirrored, but visibility differs (GitHub private=${private}, Gitea private=${gitea_private}). Syncing..." + patch_code=$(curl -s -o /tmp/gitea_patch_resp.json -w "%{http_code}" \ + -X PATCH "${GITEA_URL}/api/v1/repos/${GITEA_OWNER}/${name}" \ + -H "Authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"private\": ${private}}") + + if [ "$patch_code" == "200" ]; then + echo " Visibility updated to private=${private}." + else + echo " Failed to update visibility (HTTP ${patch_code}):" + cat /tmp/gitea_patch_resp.json + fi + else + echo " Already mirrored, visibility already matches (private=${gitea_private}). Skipping." + fi continue fi