commit 4da8ec420aa014568adc3895fc3357d51e2591d8 Author: Ashley Graves Date: Tue Oct 15 16:15:48 2024 +0200 halo diff --git a/.forgejo/workflows/mirror.yml b/.forgejo/workflows/mirror.yml new file mode 100644 index 0000000..4da5a83 --- /dev/null +++ b/.forgejo/workflows/mirror.yml @@ -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 diff --git a/mirror.sh b/mirror.sh new file mode 100755 index 0000000..c5642c8 --- /dev/null +++ b/mirror.sh @@ -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 <