Skip to content

Instantly share code, notes, and snippets.

@jepser
Created March 12, 2018 22:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jepser/aa0c078aee0a0179130bdeb9cd19a800 to your computer and use it in GitHub Desktop.
Save jepser/aa0c078aee0a0179130bdeb9cd19a800 to your computer and use it in GitHub Desktop.
Create PR to the projects that depend on your library
# Library repository
WP_SHARED_MODULES=Typeform/wp-shared-modules
# List of repositories in which you want to create a PR
REPOSITORIES=(public-website a-little-more-human helpcenter)
# Returns the name of the last tag of the repo that is being updated
get_latest_release() {
curl --silent -u ${GH_USER}:${GH_TOKEN} "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
# Updates the dependency with the latest version
update_dependency() {
git clone --depth 1 https://${GH_TOKEN}@github.com/Typeform/${1}.git
cd $1
composer update ${WP_SHARED_MODULES}@dev-master:$3
git add composer.json
git add composer.lock
git status
git commit -m "chore($WP_SHARED_MODULES): update @typeform/wp-shared-modules to '$3'" --no-verify
git push origin master:update-wp-shared-modules-to-${3} --no-verify
curl \
--silent \
-X POST \
-u ${GH_USER}:${2} \
-k -d '{"title": "Update $WP_SHARED_MODULES dependency", "body": "@typeform/wp-shared-modules: '$3'", "head": "update-wp-shared-modules-to-'$3'", "base": "master"}' \
https://api.github.com/repos/Typeform/${1}/pulls
cd ../
rm -rf $1
}
# Saves in last_release var the latest version of the plugin
last_release=$(get_latest_release ${WP_SHARED_MODULES})
echo "The release is '$last_release'"
for repo in ${REPOSITORIES[*]}
do
echo "creating PR for '$repo'"
update_dependency $repo $GH_TOKEN $last_release
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment