Skip to content

Instantly share code, notes, and snippets.

@liyinsg
Created December 23, 2020 07:25
Show Gist options
  • Save liyinsg/fbfc31ece0c23ee411b51ed191ab154e to your computer and use it in GitHub Desktop.
Save liyinsg/fbfc31ece0c23ee411b51ed191ab154e to your computer and use it in GitHub Desktop.
Batch sync all gitea repos
#!/bin/bash
GITEA_API=http://sgsxdev005.isng.intel.com:6998/api/v1
GITEA_TOKEN=xxxx24939dc220dc7fc65c04d5ee9f04f5exxxx
page=1
while true; do
JSON=$(curl -X GET "$GITEA_API/repos/search?uid=2&mode=mirror&page=${page}&limit=512&access_token=$GITEA_TOKEN" -H "accept: application/json")
NEWREPO=$(echo $JSON | python2 -c "import sys, json; print ' '.join([str(p['name']) for p in json.load(sys.stdin)['data']])")
[ -z "$NEWREPO" ] && break
REPOS+=" "$NEWREPO
(( page++ ))
done
for REPO in $REPOS
do
curl -X POST "$GITEA_API/repos/mirror/${REPO}/mirror-sync?access_token=$GITEA_TOKEN" -H "accept: application/json"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment