Skip to content

Instantly share code, notes, and snippets.

@liyinsg
Created December 23, 2020 07:23
Show Gist options
  • Save liyinsg/563af1849a57cb4c3593c145e64c2df6 to your computer and use it in GitHub Desktop.
Save liyinsg/563af1849a57cb4c3593c145e64c2df6 to your computer and use it in GitHub Desktop.
repo to gitea batch migration
#!/bin/bash
# repo forall -c /path/to/migrate.sh
GITEA_REPO=/local/yinli/repos/mirror
GITEA_API=http://sgsxdev005.isng.intel.com:6998/api/v1
GITEA_TOKEN=xxxx24939dc220dc7fc65c04d5ee9f04f5exxxx
REMOTE_URL=https://gts-chd.intel.com/scm
REMOTE_PASS="password"
REMOTE_USER="yinli"
migrate()
{
repo=${REPO_PROJECT}
GIT_DIR=${GITEA_REPO}/${repo}.git
[ -d "${GIT_DIR}" ] && return
echo "migrating ${repo}..."
curl -X POST "${GITEA_API}/repos/migrate?access_token=${GITEA_TOKEN}" -H "accept: application/json" -H "Content-Type: application/json" -d \
"{ \"auth_password\": \"${REMOTE_PASS}\", \"auth_username\": \"${REMOTE_USER}\", \"clone_addr\": \"${REMOTE_URL}/${REPO_REMOTE}/${repo}.git\", \"issues\": false, \"labels\": false, \"milestones\": false, \"mirror\": true, \"private\": false, \"pull_requests\": false, \"releases\": false, \"repo_name\": \"${repo}\", \"uid\": 2, \"wiki\": false}"
echo "change settings..."
curl -X PATCH "${GITEA_API}/repos/mirror/${repo}?access_token=${GITEA_TOKEN}" -H "accept: application/json" -H "Content-Type: application/json" -d \
"{ \"has_issues\": false, \"has_pull_requests\": false, \"has_wiki\": false, \"default_branch\": \"${REPO_RREV}\"}"
cd ${GIT_DIR} && git remote set-url origin ssh://[email protected]:29418/${REPO_REMOTE}/${repo}
}
[ -z $REPO_REMOTE ] && exit -1
[ -z $REPO_PROJECT ] && exit -1
[ -z $REPO_RREV ] && exit -1
migrate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment