Skip to content

Instantly share code, notes, and snippets.

@blaggacao
Created June 19, 2019 01:54
Show Gist options
  • Save blaggacao/e7e324d53aee7304fb3f5a48199874e8 to your computer and use it in GitHub Desktop.
Save blaggacao/e7e324d53aee7304fb3f5a48199874e8 to your computer and use it in GitHub Desktop.
One Module On Repo (OMOR) for OCA
#!/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=SECRET
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 "git@github.com: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