Created
December 6, 2017 22:54
-
-
Save blaggacao/e8e514d0ad7fe9e3355fe6dd0ae9474b to your computer and use it in GitHub Desktop.
Rip Odoo repos and create 1by1 module repos
This file contains 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 | |
SCRIPT=$(realpath -s $0) | |
SCRIPTPATH=$(dirname $SCRIPT) | |
urls=$(curl "https://api.github.com/users/$1/repos?page=$2&per_page=100" | grep -e 'git_url*' | cut -d \" -f 4) | |
gitub_api_token=TOKEN | |
branch_list="8.0 9.0 10.0 11.0" | |
module_exclude_list="setup .git" | |
# # Create an organization | |
# curl -i -H "Authorization: token $gitub_api_token" \ | |
# -d "{ \ | |
# \"login\": \"xoes-$1\", \ | |
# \"profile_name\": \"XOE's 1by1 of $1\", \ | |
# \"admin\": \"blaggacao\" \ | |
# }" https://api.github.com/admin/organizations || true | |
for url in $urls; do | |
basename=$(basename $url) | |
reponame=${basename%.*} | |
cd $SCRIPTPATH | |
git clone "$url" "$SCRIPTPATH/$reponame" | |
cd $SCRIPTPATH/$reponame | |
branches=() | |
eval "$(git for-each-ref --shell --format='branches+=(%(refname))' refs/remotes/origin/)" | |
for branch in "${branches[@]}"; do | |
branch=$(echo "${branch}" | cut -d'/' -f 4) | |
echo "ECHO 1 $branch" | |
if echo $branch_list | grep -w $branch; then | |
git checkout $branch | |
echo "ECHO 2 $branch" | |
for path in $(find . -maxdepth 1 -mindepth 1 -type d -printf '%f\n'); do | |
if echo $module_exclude_list | grep -w $path > /dev/null; then | |
continue | |
fi | |
echo "ECHO 3 $branch $path" | |
curl -i -H "Authorization: token $gitub_api_token" \ | |
-d "{ \"name\": \"${path}\", \"description\": \"1by1 module copy from repository github.com/$1/$reponame\"}" \ | |
https://api.github.com/orgs/xoes-$1/repos | |
git subrepo init "${path}" -r "[email protected]:xoes-$1/${path}.git" -b "${branch}" | |
git subrepo push "${path}" | |
done | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment