#!/usr/bin/env sh

echo "launching new chrome window..."
/usr/bin/open -n -a "/Applications/Google Chrome.app"

echo "creating tags ..."
function incrementTag {
	v=$1
	echo "${v%.*}.$((${v##*.}+1))"
}

function updateTag {
	cd $1 &&
	git checkout master -q &&
	git pull -q &&
	git pull --tags -q &&
	version=$(incrementTag $(git tag --sort version:refname | tail -n 1))
	echo "new version is: $version"
	git commit --allow-qempty -m "$version"
	git push origin master
	git tag "$version"
	git push --tags origin master
}

updateTag ~/work/extensions/importers/Paw-RAMLImporter
updateTag ~/work/extensions/importers/Paw-SwaggerImporter
updateTag ~/work/extensions/importers/Paw-PostmanImporter
updateTag ~/work/extensions/importers/Paw-cURLImporter
updateTag ~/work/extensions/generators/Paw-RAMLGenerator
updateTag ~/work/extensions/generators/Paw-SwaggerGenerator
updateTag ~/work/extensions/generators/Paw-PostmanDumpGenerator
updateTag ~/work/extensions/generators/Paw-MarkdownCurlGenerator

sleep 1
echo "opening relevant pages ..."
# importers
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-PostmanImporter/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/10/change/'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-RAMLImporter/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/59/change/'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-cURLImporter/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/35/change/'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-SwaggerImporter/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/24/change/'
# generators
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-PostmanDumpGenerator/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/68/change/'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-MarkdownCurlGenerator/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/69/change/'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-RAMLGenerator/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/70/change/'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://github.com/luckymarmot/Paw-SwaggerGenerator/releases/new'
/usr/bin/open -a "/Applications/Google Chrome.app" 'https://paw.cloud/admin/extensions/extension/71/change/'

