From b5faac0144690381c4c34db3c01ebb00310c9e41 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Sat, 8 Feb 2014 16:49:07 +0100 Subject: [PATCH] Add repository search Qualifiers can be added via keyword args in order to keep the method uncluttered. Qualifiers could also be given in the query string directly. --- github/MainClass.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/github/MainClass.py b/github/MainClass.py index 4239ce5a..dc718943 100644 --- a/github/MainClass.py +++ b/github/MainClass.py @@ -290,6 +290,41 @@ class Github(object): ) return github.NamedUser.NamedUser(self.__requester, headers, Legacy.convertUser(data["user"]), completed=False) + def search_repositories(self, query, sort=github.GithubObject.NotSet, order=github.GithubObject.NotSet, **qualifiers): + """ + :calls: `GET /search/repositories `_ + :param query: string + :param sort: string ('stars', 'forks', 'updated') + :param order: string ('asc', 'desc') + :param qualifiers: keyword dict query qualifiers + :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Repository.Repository` + """ + assert isinstance(query, (str, unicode)), query + url_parameters = dict() + if sort is not github.GithubObject.NotSet: + assert sort in ('stars', 'forks', 'updated'), sort + url_parameters["sort"] = sort + if order is not github.GithubObject.NotSet: + assert order in ('asc', 'desc'), order + url_parameters["order"] = order + + query_chunks = [] + if query: + query_chunks += query.split() + + for qualifier, value in qualifiers.items(): + query_chunks.append("%s:%s" % (qualifier, value)) + + url_parameters["q"] = ' '.join(query_chunks) + assert url_parameters["q"], "need at least one qualifier" + + return github.PaginatedList.PaginatedList( + github.Repository.Repository, + self.__requester, + "/search/repositories", + url_parameters + ) + def render_markdown(self, text, context=github.GithubObject.NotSet): """ :calls: `POST /markdown `_