@@ -45,8 +45,7 @@ import os
45
45
import re
46
46
47
47
def main ():
48
- global repo
49
- repo = ''
48
+ repo , remote = '' , None
50
49
51
50
# parse command line options
52
51
try :
@@ -61,32 +60,39 @@ def main():
61
60
print __doc__
62
61
sys .exit (0 )
63
62
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'
65
70
66
71
# get repo name from git config:
67
72
if (repo == '' ):
68
73
repo = os .popen ('git config github.repo' ).read ().strip ()
69
74
70
75
# get repo name from origin
71
- if (repo == '' ):
76
+ if (repo == '' or remote != None ):
72
77
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 )
74
79
if (m != None and m .group (1 ) != '' ):
75
80
repo = m .group (1 )
76
81
77
82
if (repo == '' ):
78
83
print color_text ("Failed to determine github repository name" ,'red' ,True )
79
84
print "The repository is usually automatically detected from your remote origin."
80
85
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"
82
88
print "git config github.repo <user>/<repository>"
83
89
sys .exit (1 )
84
90
85
91
# process arguments
86
92
if len (args ):
87
- ret = fetch (args [0 ])
93
+ ret = fetch (repo , args [0 ])
88
94
else :
89
- ret = show ()
95
+ ret = show (repo )
90
96
91
97
sys .exit (ret )
92
98
@@ -108,14 +114,18 @@ def display(pr):
108
114
109
115
Queries the github API for open pull requests in the current repo
110
116
"""
111
- def show ():
112
- global repo
117
+ def show (repo ):
113
118
114
119
print "loading open pull requests for %s..." % (repo )
115
120
print
116
121
url = "http://github.com/api/v2/json/pulls/%s/open" % (repo )
117
122
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
+
119
129
data = response .read ()
120
130
if (data == '' ):
121
131
print "failed to speak with github."
@@ -129,8 +139,7 @@ def show():
129
139
return 0
130
140
131
141
132
- def fetch (pullreq ):
133
- global repo
142
+ def fetch (repo , pullreq ):
134
143
135
144
print "loading pull request info for request %s..." % (pullreq )
136
145
print
@@ -143,7 +152,6 @@ def fetch(pullreq):
143
152
return 3
144
153
145
154
data = json .loads (data )
146
- #print json.dumps(data,sort_keys=True, indent=4)
147
155
pr = data ['pull' ]
148
156
display (pr )
149
157
0 commit comments