mirror of
https://github.com/kennethreitz-archive/github2.git
synced 2026-06-05 23:50:18 +00:00
* 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:
+15
-1
@@ -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")
|
||||
|
||||
|
||||
@@ -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"])
|
||||
|
||||
Reference in New Issue
Block a user