Skip to content

Instantly share code, notes, and snippets.

@yardnsm
Last active January 6, 2019 08:06
Show Gist options
  • Save yardnsm/c6008d0f87d847e81eb3afc3790b6f98 to your computer and use it in GitHub Desktop.
Save yardnsm/c6008d0f87d847e81eb3afc3790b6f98 to your computer and use it in GitHub Desktop.
A small executable to ease the navigation for WSR's PRs live stories
#!/usr/bin/env bash
info() {
local bold=$(tput bold)
local normal=$(tput sgr0)
printf "${bold}$1:${normal}\\t $2\\n"
}
green() {
echo "$(tput setaf 2)$1$(tput sgr0)"
}
get_git_branch () {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
echo "${ref#refs/heads/}"
}
# --------------------------------------------------------------------------------------------------
main() {
local branch_name="$(get_git_branch)"
local pr_number="$(hub pr list --head=${branch_name} | awk '{ print $1 }' | cut -d '#' -f2)"
local pr_home="https://github.com/wix/wix-style-react/"
local surge_url="https://wix-wix-style-react.surge.sh/"
echo
info "Current branch name" "$branch_name"
if [[ "$branch_name" != "master" ]]; then
if [[ -z "$pr_number" ]]; then
echo
echo "No PR is available for this branch :("
echo
green "Opening Surge story..."
open "$surge_url"
return 1
fi
pr_home="https://github.com/wix/wix-style-react/pull/${pr_number}/"
surge_url="https://wix-wix-style-react-pr-${pr_number}.surge.sh/"
info "Pull Request number" "#${pr_number}"
fi
echo
info "Pull Request URL" "${pr_home}"
info "Surge live story" "${surge_url}"
echo
local surge_res_code="$(curl -s -o /dev/null -w '%{http_code}' "$surge_url")"
if [[ "$1" == "pr" ]] || [[ "$surge_res_code" == "404" ]]; then
green "Opening PR URL..."
open "$pr_home"
else
green "Opening Surge story..."
open "$surge_url"
fi
}
main "$@"
@yardnsm
Copy link
Author

yardnsm commented Jan 6, 2019

Usage

Run the executable via:

$ wsr

It will:

  • Open the public "regular" story if current branch has not associated PR.
  • Will open the PR's live story if it was deployed successfully.
  • Will open the PR page if the story has not been deployed yet.

You can also run:

$ wsr pr

and it will open the PR page anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment