Created
April 19, 2022 09:51
-
-
Save ltupin/e88b5301acf24090c907eba07b29e6c8 to your computer and use it in GitHub Desktop.
Copy a git repo from Github to AWS codecommit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| if [ ${#@} -lt 2 ]; then | |
| echo "usage: $0 [your github token] [your organisation name]" | |
| exit 1; | |
| fi | |
| GITHUB_TOKEN=$1 # github_key | |
| PROJECT=$2 # organisation | |
| ORGANISATION=/orgs/$2/repos | |
| GITHUB_HEADER="Accept: application/vnd.github.v3+json" | |
| last_page=`curl -s -I "https://api.github.com${ORGANISATION}" -H "${GITHUB_HEADER}" -H "Authorization: token ${GITHUB_TOKEN}" | grep '^link:' | sed -e 's/^link:.*page=//g' -e 's/>.*$//g'` | |
| function pullpush() | |
| { | |
| export repo_name=$(curl -s https://api.github.com${ORGANISATION}?page=$p -H "${GITHUB_HEADER}" -H "Authorization: token ${GITHUB_TOKEN}" | jq -r '.[].html_url' | sed 's:.*/::' | sed 's/\.$//') | |
| for repo in ${repo_name}: | |
| do echo -e "\n" | |
| git clone [email protected]:${PROJECT}/$(echo ${repo} | sed 's/://').git | |
| cd $(echo ${repo} | sed 's/://') | |
| for branch in `git branch -a | grep remotes | grep -v HEAD`; do | |
| git branch --track ${branch#remotes/origin/} ${branch} | |
| sed -i'' -e 's/[email protected]:$2\//codecommit::eu-west-1:\/\/github-/g' .git/config | |
| git push --all origin | |
| done | |
| cd .. | |
| done | |
| } | |
| if [ -z "${last_page}" ]; then | |
| # One page | |
| pullpush | |
| else | |
| # Pagination | |
| for p in `seq 1 ${last_page}`; do | |
| pullpush | |
| done | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment