diff --git a/github/Organization.py b/github/Organization.py index a3fc0083..26215a89 100644 --- a/github/Organization.py +++ b/github/Organization.py @@ -760,16 +760,25 @@ class Organization(github.GithubObject.CompletableGithubObject): ) return github.Repository.Repository(self._requester, headers, data, completed=True) - def get_repos(self, type=github.GithubObject.NotSet): + def get_repos(self, type=github.GithubObject.NotSet, sort=github.GithubObject.NotSet, direction=github.GithubObject.NotSet): """ :calls: `GET /orgs/:org/repos `_ :param type: string ('all', 'public', 'private', 'forks', 'sources', 'member') + :param sort: string ('created', 'updated', 'pushed', 'full_name') + :param direction: string ('asc', desc') :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` """ assert type is github.GithubObject.NotSet or isinstance(type, (str, unicode)), type + assert sort is github.GithubObject.NotSet or isinstance(sort, (str, unicode)), sort + assert direction is github.GithubObject.NotSet or isinstance(direction, (str, unicode)), direction + url_parameters = dict() if type is not github.GithubObject.NotSet: url_parameters["type"] = type + if sort is not github.GithubObject.NotSet: + url_parameters["sort"] = sort + if direction is not github.GithubObject.NotSet: + url_parameters["direction"] = direction return github.PaginatedList.PaginatedList( github.Repository.Repository, self._requester, diff --git a/tests/Organization.py b/tests/Organization.py index 7ec20a35..8ad8829d 100644 --- a/tests/Organization.py +++ b/tests/Organization.py @@ -179,6 +179,9 @@ class Organization(Framework.TestCase): def testGetRepos(self): self.assertListKeyEqual(self.org.get_repos(), lambda r: r.name, ["FatherBeaver", "TestPyGithub"]) + def testGetReposSorted(self): + self.assertListKeyEqual(self.org.get_repos(sort = "updated", direction = "desc"), lambda r: r.name, ["TestPyGithub", "FatherBeaver"]) + def testGetReposWithType(self): self.assertListKeyEqual(self.org.get_repos("public"), lambda r: r.name, ["FatherBeaver", "PyGithub"]) diff --git a/tests/ReplayData/Organization.testGetReposSorted.txt b/tests/ReplayData/Organization.testGetReposSorted.txt new file mode 100644 index 00000000..ace94143 --- /dev/null +++ b/tests/ReplayData/Organization.testGetReposSorted.txt @@ -0,0 +1,11 @@ +https +GET +api.github.com +None +/orgs/BeaverSoftware/repos?sort=updated&direction=desc +{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'} +None +200 +[('status', '200 OK'), ('x-ratelimit-remaining', '4978'), ('content-length', '2300'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"56a6b76672924aa7f1d6f1753388f04b"'), ('date', 'Sun, 27 May 2012 05:12:35 GMT'), ('content-type', 'application/json; charset=utf-8')] +[{"clone_url":"https://github.com/BeaverSoftware/TestPyGithub.git","has_downloads":true,"watchers":1,"git_url":"git://github.com/BeaverSoftware/TestPyGithub.git","updated_at":"2012-04-25T06:51:38Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"http://vincent-jacques.net/PyGithub","url":"https://api.github.com/repos/BeaverSoftware/TestPyGithub","has_wiki":true,"has_issues":false,"fork":false,"forks":0,"mirror_url":null,"size":112,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/TestPyGithub","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"name":"TestPyGithub","language":null,"description":"Guinea-pig for PyGithub testing","ssh_url":"git@github.com:BeaverSoftware/TestPyGithub.git","pushed_at":"2012-03-03T08:57:40Z","created_at":"2012-03-03T07:53:19Z","id":3609352,"html_url":"https://github.com/BeaverSoftware/TestPyGithub","full_name":"BeaverSoftware/TestPyGithub"},{"clone_url":"https://github.com/BeaverSoftware/FatherBeaver.git","has_downloads":true,"watchers":2,"git_url":"git://github.com/BeaverSoftware/FatherBeaver.git","updated_at":"2012-02-16T21:51:15Z","permissions":{"pull":true,"admin":true,"push":true},"homepage":"","url":"https://api.github.com/repos/BeaverSoftware/FatherBeaver","has_wiki":true,"has_issues":true,"fork":false,"forks":1,"mirror_url":null,"size":0,"private":false,"open_issues":0,"svn_url":"https://github.com/BeaverSoftware/FatherBeaver","owner":{"url":"https://api.github.com/users/BeaverSoftware","gravatar_id":"d563e337cac2fdc644e2aaaad1e23266","login":"BeaverSoftware","id":1424031,"avatar_url":"https://secure.gravatar.com/avatar/d563e337cac2fdc644e2aaaad1e23266?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-orgs.png"},"name":"FatherBeaver","language":null,"description":"","ssh_url":"git@github.com:BeaverSoftware/FatherBeaver.git","pushed_at":null,"created_at":"2012-02-09T19:32:21Z","id":3400397,"html_url":"https://github.com/BeaverSoftware/FatherBeaver","full_name":"BeaverSoftware/FatherBeaver"}] +