51 lines
1.4 KiB
Bash
Executable file
51 lines
1.4 KiB
Bash
Executable file
#!/bin/bash
|
|
PER_PAGE=50
|
|
PAGE=1
|
|
|
|
fetch_and_mirror() {
|
|
local page_url="https://api.github.com/users/${GITHUB_USER}/starred?per_page=${PER_PAGE}&page=${PAGE}"
|
|
|
|
# Fetch the current page of repositories
|
|
response=$(curl -s -I "$page_url")
|
|
|
|
# Extract links from the response headers
|
|
links=$(echo "$response" | grep -i '^Link:' | sed -e 's/Link: //')
|
|
|
|
# Parse the repositories and mirror them
|
|
curl -s "$page_url" | jq -r '.[] | [.name, .html_url] | @tsv' | \
|
|
while IFS=$'\t' read -r repo url; do
|
|
echo "Mirroring repository: $repo"
|
|
json_payload=$(cat <<EOF
|
|
{
|
|
"clone_addr": "$url",
|
|
"repo_name": "$repo",
|
|
"mirror": true,
|
|
"repo_owner": "mirrors",
|
|
"description": "Mirror of $url",
|
|
"private": false,
|
|
"issues": false,
|
|
"pull_requests": false
|
|
}
|
|
EOF
|
|
)
|
|
curl -svi \
|
|
-X POST \
|
|
-H "Accept: application/json" \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: token $FORGEJO_TOKEN" \
|
|
-d "$json_payload" \
|
|
$FORGEJO_URL/api/v1/repos/migrate
|
|
done
|
|
|
|
# Check if there's a 'next' link
|
|
if echo "$links" | grep -q 'rel="next"'; then
|
|
PAGE=$((PAGE+1))
|
|
# Give forgejo and my disk a break
|
|
echo "Waiting 1 minute before continuing to the next page"
|
|
sleep 60
|
|
fetch_and_mirror # Recursively call the function to process the next page
|
|
fi
|
|
}
|
|
|
|
# Start the process
|
|
fetch_and_mirror
|