halo
All checks were successful
/ update (push) Successful in 7s

This commit is contained in:
Ashley Graves 2024-10-15 16:15:48 +02:00
commit 4da8ec420a
2 changed files with 71 additions and 0 deletions

View file

@ -0,0 +1,21 @@
on:
workflow_dispatch:
push:
schedule:
- cron: "* * * * *"
env:
FORGEJO_URL: ${{ vars.FORGEJO_URL }}
FORGEJO_USER: ${{ vars.FORGEJO_USER }}
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
GITHUB_USER: ${{ vars.GH_USER }}
jobs:
update:
runs-on: ubuntu-latest
steps:
- name: Checkout client
uses: actions/checkout@v3
- name: Run mirror script
run: ./mirror.sh

50
mirror.sh Executable file
View file

@ -0,0 +1,50 @@
#!/bin/bash
PER_PAGE=50
PAGE=1
fetch_and_mirror() {
local page_url="https://api.github.com/users/${GITHUB_API_URL}/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: $name"
json_payload=$(cat <<EOF
{
"clone_addr": "$url",
"repo_name": "$name",
"mirror": true,
"repo_owner": "mirrors",
"description": "Mirror of $url",
"private": false,
"issues": false,
"pull_requests": false
}
EOF
)
curl -s -u $FORGEJO_USER:$FORGEJO_TOKEN \
-X POST \
-H "Content-Type: application/json" \
--data "$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 30
fetch_and_mirror # Recursively call the function to process the next page
fi
}
# Start the process
fetch_and_mirror