Skip to content

Instantly share code, notes, and snippets.

@phwelo
Created October 18, 2019 03:50
Show Gist options
  • Save phwelo/d8d0a1d427859740ff822beebb6e73da to your computer and use it in GitHub Desktop.
Save phwelo/d8d0a1d427859740ff822beebb6e73da to your computer and use it in GitHub Desktop.
Automatically browse to create PR for master/current branch
#!/usr/bin/env python3
import subprocess
BROWSER = "vivaldi-snapshot"
def git_remote_to_url(branch):
remotev = subprocess.check_output(["git", "remote", "-v"]).decode("utf-8")
remote = remotev.split('\t')[1].split(' (fetch)')[0]
url = convert_uri(remote)
return url
def git_branch():
status = subprocess.check_output(["git", "status"]).decode("utf-8")
branch = status.split("\n")[0].split(" ")[2]
return branch
def convert_uri(uri):
uri_base = uri.split("github.com:")[1].rstrip(".git")
web_url = "http://www.github.com/" + uri_base + "/compare/master..." + git_branch()
return web_url
branch = git_branch()
url = git_remote_to_url(branch)
print(url)
subprocess.Popen([BROWSER, url], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment