Skip to content

Instantly share code, notes, and snippets.

@freman
Created March 14, 2017 04:11
Show Gist options
  • Save freman/c4715a3ccb626ed6f1cafa628db1583f to your computer and use it in GitHub Desktop.
Save freman/c4715a3ccb626ed6f1cafa628db1583f to your computer and use it in GitHub Desktop.
Convert go-micro to stdlib context
#!/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+=("git@github.com:${user}${project}.git")
NEW_REPOS+=("git@github.com:${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