Skip to content

Instantly share code, notes, and snippets.

@stephenmcd
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephenmcd/664e0ca25917d372f310 to your computer and use it in GitHub Desktop.
Save stephenmcd/664e0ca25917d372f310 to your computer and use it in GitHub Desktop.
My Github pull request pull script for Mercurial
#!/usr/bin/env python
import os
import sys
import github
username = "stephenmcd"
while True:
repo = os.getcwd()
if os.path.isdir(".hg"):
with open(".hg/hgrc", "r") as f:
found = False
for line in f:
if found:
repo = line.split("/")[-1].strip()
break
found = found or line.strip() == "[paths]"
break
os.chdir("..")
if os.getcwd() == repo:
repo = None
break
pull_id = sys.argv[-1]
if pull_id.isdigit() and repo is not None:
gh = github.GitHub()
pr = gh.repos(username)(repo).pulls(pull_id).get()
contributor, branch = pr["head"]["label"].split(":", 1)
bits = (contributor, repo, branch)
os.system("hg pull git+ssh://git@github.com/%s/%s.git -r %s" % bits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment