Created
March 14, 2017 04:11
-
-
Save freman/c4715a3ccb626ed6f1cafa628db1583f to your computer and use it in GitHub Desktop.
Convert go-micro to stdlib context
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 | |
NEW_USER="divisionone" | |
PACKAGES=( | |
"github.com/micro/go-micro" | |
"github.com/micro/protobuf" | |
) | |
SEDS=( | |
's,golang.org/x/net/context,context,' | |
) | |
ORG_REPOS=() | |
NEW_REPOS=() | |
for package in ${PACKAGES[@]}; do | |
if [[ "${package}" =~ (github.com\/)(.+)(\/.+) ]]; then | |
user=${BASH_REMATCH[2]} | |
project=${BASH_REMATCH[3]} | |
ORG_REPOS+=("[email protected]:${user}${project}.git") | |
NEW_REPOS+=("[email protected]:${NEW_USER}${project}.git") | |
SEDS+=("s,github.com/${user}\\(${project}[/\"]\\),github.com/${NEW_USER}\\1,") | |
else | |
echo "Unable to parse package $package}" | |
fi | |
done | |
sedallthethings() { | |
for s in ${SEDS[@]}; do | |
find "$1" -type f -name "*.go" -exec sed -i '' "$s" {} \; | |
done | |
} | |
for i in "${!ORG_REPOS[@]}"; do | |
workdir=$(basename -s '.git' "${ORG_REPOS[$i]}") | |
if [ -d "$workdir" ]; then | |
( | |
cd $workdir | |
git reset --hard origin/master | |
orgrev=$(git rev-parse HEAD) | |
git pull | |
if [ "${orgrev}" != "$(git rev-parse HEAD)" ]; then | |
sedallthethings "." | |
git add . | |
git commit -m "STDLIB" | |
git push stdlib master --force | |
fi | |
) | |
else | |
git clone ${ORG_REPOS[$i]} | |
sedallthethings "$workdir" | |
( | |
cd $workdir | |
git remote add stdlib "${NEW_REPOS[$i]}" | |
git add . | |
git commit -m "STDLIB" | |
git push stdlib master --force | |
) | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment