Last active
August 29, 2015 14:21
-
-
Save stephenmcd/664e0ca25917d372f310 to your computer and use it in GitHub Desktop.
My Github pull request pull script for Mercurial
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 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