Rando scripts

Andrei Matei edited this page Feb 12, 2016 · 14 revisions
  • Get a PR locally, or create a PR from the current branch.
    Curtesy of Tamir.
    TODO: refuse to create a PR if the current branch diverged from the tracker.
#!/usr/bin/env sh

set -eu

error_message() {
  ret=$?
  if [ $ret -ne 0 ]; then
    echo "Something went wrong. Did you push your branch? Did you set a remote tracking branch?"
  fi
  exit $ret
}

trap error_message EXIT

if [ $# == 0 ]; then
  branch_name=$(git rev-parse --abbrev-ref HEAD)
  remote_name=$(git config branch."$branch_name".remote)

  github_forked_org_name=$(git config remote."$remote_name".url | sed -E -e 's,^(https://|git@)github.com[:/]([a-z]+)/[a-z]+(\.git)?,\2,')
  github_origin_proj_url=$(git config remote.origin.url         | sed -E -e 's,^(https://|git@)github.com[:/]([a-z]+/[a-z]+)(\.git)?,\2,')

  url="https://github.com/$github_origin_proj_url/compare/master...$github_forked_org_name:$branch_name?expand=1#files_bucket"

  open "$url"
else
  hub fetch origin refs/pull/"$1"/head:pr/"$1" && hub checkout pr/"$1"
fi
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.