Refactor mirror script to streamline repo processing and improve payload construction

This commit is contained in:
2026-08-18 16:30:44 +03:00
parent 1bdc15b258
commit a752daff3d
+21 -15
View File
@@ -26,7 +26,7 @@ done
total=$(echo "$repos_json" | jq 'length')
echo "Found ${total} repos on GitHub for ${GITHUB_USER}"
echo "$repos_json" | jq -c '.[] | {name, private}' | while read -r entry; do
while read -r entry; do
name=$(echo "$entry" | jq -r '.name')
private=$(echo "$entry" | jq -r '.private')
@@ -62,23 +62,29 @@ echo "$repos_json" | jq -c '.[] | {name, private}' | while read -r entry; do
continue
fi
payload=$(jq -n \
--arg clone_addr "https://github.com/${GITHUB_USER}/${name}.git" \
--arg repo_name "$name" \
--arg repo_owner "$GITEA_OWNER" \
--arg mirror_interval "$MIRROR_INTERVAL" \
--argjson private "$private" \
--arg auth_token "$GITHUB_TOKEN" \
'{
clone_addr: $clone_addr,
repo_name: $repo_name,
repo_owner: $repo_owner,
mirror: true,
mirror_interval: $mirror_interval,
private: $private,
service: "github",
auth_token: $auth_token
}')
http_code=$(curl -s -o /tmp/gitea_migrate_resp.json -w "%{http_code}" \
-X POST "${GITEA_URL}/api/v1/repos/migrate" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"clone_addr": "https://github.com/${GITHUB_USER}/${name}.git",
"repo_name": "${name}",
"repo_owner": "${GITEA_OWNER}",
"mirror": true,
"mirror_interval": "${MIRROR_INTERVAL}",
"private": ${private},
"service": "github",
"auth_token": "${GITHUB_TOKEN}"
}
EOF
)
--data-raw "$payload")
if [ "$http_code" == "201" ]; then
echo " Created mirror (private=${private})."
@@ -88,6 +94,6 @@ EOF
fi
sleep 1 # be gentle on both APIs
done
done < <(echo "$repos_json" | jq -c '.[] | {name, private}')
echo "Done."