scripts/github_star_mirror.sh
2024-03-09 11:55:43 +01:00

20 lines
656 B
Bash
Executable file

#/!/bin/bash
# Gets the 100 most recently starred repositories of $GITHUB_USER, and creates Mirrors on $FORGEJO_URL
# Dependencies: jq & curl
# env vars:
# GITHUB_USER
# FORGEJO_USER
# FORGEJO_TOKEN (password or api token)
# FORGEJO_URL
curl https://api.github.com/users/$GITHUB_USER/starred\?per_page\=100\&page\=1 |
jq -r '.[] | [.name, .html_url] | @tsv' |
while i=$'\t' read -r name url; do
curl \
-u $FORGEJO_USER:$FORGEJO_TOKEN \
-X POST \
-H "Content-Type: application/json" \
--data "{\"clone_addr\": \"$url\", \"repo_name\": \"$name\", \"mirror\": true, \"repo_owner\": \"Mirrors\"}" \
$FORGEJO_URL/api/v1/repos/migrate
done