* raise a somewhat more helpfull exception when github.com returns an error

* added docstrings on some functions which made me stumble
This commit is contained in:
Maximillian Dornseif
2010-01-01 10:36:04 +01:00
parent b44bcf82d6
commit 3dd8d9e854
2 changed files with 18 additions and 1 deletions
+15 -1
View File
@@ -28,9 +28,14 @@ class Repositories(GithubCommand):
datatype=Repository)
def list(self, for_user=None):
"""Return a list of all repositories for a user.
If no user is given, repositoris for the currently logged in user are
returned.
"""
for_user = for_user or self.request.username
return self.get_values("show", for_user, filter="repositories",
datatype=Repository)
datatype=Repository)
def watch(self, project):
return self.make_request("watch", project)
@@ -58,13 +63,22 @@ class Repositories(GithubCommand):
return self.make_request("set/public", repo_name)
def list_collaborators(self, project):
"""Lists all the collaborators in a project (user/repro)."""
return self.make_request("show", project, "collaborators",
filter="collaborators")
def add_collaborator(self, repo_name, username):
"""Adds an add_collaborator to a repro.
Do not prefix repro_name with the user owning the repro like you
do in list_collaborators()"""
return self.make_request("collaborators", repo_name, "add", username)
def remove_collaborator(self, repo_name, username):
"""Removes an add_collaborator from a repro.
Do not prefix repro_name with the user owning the repro like you
do in list_collaborators()"""
return self.make_request("collaborators", repo_name, "remove",
username, method="POST")
+3
View File
@@ -78,6 +78,9 @@ class GithubRequest(object):
if self.debug:
sys.stderr.write("URL:[%s] POST_DATA:%s RESPONSE_TEXT: [%s]\n" % (
path, post_data, response_text))
if response.status >= 400:
raise RuntimeError("unexpected response from github.com %d: %r" % (
response.status, response_text))
json = simplejson.loads(response_text)
if json.get("error"):
raise self.GithubError(json["error"][0]["error"])