-
-
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
This file contains 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
#!/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 "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
Run the executable via:
$ wsr
It will:
You can also run:
$ wsr pr
and it will open the PR page anyways.