Skip to content

Commit 4f1f86a

Browse files
committed
Merge branch 'master' of https://github.com/mattmatt/git-pull-request into pull-request-2
2 parents ba5d3c5 + ddeb0e3 commit 4f1f86a

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

git-pull-request

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ import os
4545
import re
4646

4747
def main():
48-
global repo
49-
repo = ''
48+
repo, remote = '', None
5049

5150
# parse command line options
5251
try:
@@ -61,32 +60,39 @@ def main():
6160
print __doc__
6261
sys.exit(0)
6362
if o in ("-r", "--repo"):
64-
repo = a
63+
if re.search('/', a):
64+
repo = a
65+
else:
66+
remote = a
67+
68+
if remote is None and repo == '':
69+
remote = 'origin'
6570

6671
# get repo name from git config:
6772
if(repo == ''):
6873
repo = os.popen('git config github.repo').read().strip()
6974

7075
# get repo name from origin
71-
if(repo == ''):
76+
if(repo == '' or remote != None):
7277
origin = os.popen('git remote -v').read()
73-
m = re.search('^origin.*?github\.com.*?[:/]([^/]+/[^/]+)\.git\s*\(fetch\)$',origin,re.MULTILINE)
78+
m = re.search("^%s.*?github\.com.*?[:/]([^/]+/[^/]+)\.git\s*\(fetch\)$" % remote, origin,re.MULTILINE)
7479
if(m != None and m.group(1) != ''):
7580
repo = m.group(1)
7681

7782
if(repo == ''):
7883
print color_text("Failed to determine github repository name",'red',True)
7984
print "The repository is usually automatically detected from your remote origin."
8085
print "If your origin doesn't point to github, you can specify the repository on"
81-
print "the command line using the -r parameter or configure it using"
86+
print "the command line using the -r parameter, by specifying either a remote or"
87+
print "the full repository name (user/repo), or configure it using"
8288
print "git config github.repo <user>/<repository>"
8389
sys.exit(1)
8490

8591
# process arguments
8692
if len(args):
87-
ret = fetch(args[0])
93+
ret = fetch(repo, args[0])
8894
else:
89-
ret = show()
95+
ret = show(repo)
9096

9197
sys.exit(ret)
9298

@@ -108,14 +114,18 @@ def display(pr):
108114
109115
Queries the github API for open pull requests in the current repo
110116
"""
111-
def show():
112-
global repo
117+
def show(repo):
113118

114119
print "loading open pull requests for %s..." % (repo)
115120
print
116121
url = "http://github.com/api/v2/json/pulls/%s/open" % (repo)
117122
req = urllib2.Request(url)
118-
response = urllib2.urlopen(req)
123+
try:
124+
response = urllib2.urlopen(req)
125+
except urllib2.HTTPError, msg:
126+
print "error loading pull requests for repo %s: %s" % (repo, msg)
127+
exit(1)
128+
119129
data = response.read()
120130
if (data == ''):
121131
print "failed to speak with github."
@@ -129,8 +139,7 @@ def show():
129139
return 0
130140

131141

132-
def fetch(pullreq):
133-
global repo
142+
def fetch(repo, pullreq):
134143

135144
print "loading pull request info for request %s..." % (pullreq)
136145
print
@@ -143,7 +152,6 @@ def fetch(pullreq):
143152
return 3
144153

145154
data = json.loads(data)
146-
#print json.dumps(data,sort_keys=True, indent=4)
147155
pr = data['pull']
148156
display(pr)
149157

0 commit comments

Comments
 (0)